# Add a Dev Container to a .NET Solution

Yes. An agent writes a devcontainer.json that matches a .NET solution's SDK pin and tools, builds it, runs the tests inside, and opens a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/add-dev-containers/dotnet/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads what a working machine for the solution has to have. In a reference app like dotnet/eShop, `global.json` pins the SDK to `10.0.302` with `rollForward: latestFeature`, sets `Microsoft.Testing.Platform` as the test runner and `MSTest.Sdk` 4.0.2 as an MSBuild SDK; `aspire.config.json` names `src/eShop.AppHost/eShop.AppHost.csproj` as the AppHost and pins the Aspire SDK to 13.6.0, and `.aspire/settings.json` repeats the path. The README's prerequisites are a .NET 10 SDK that satisfies `global.json`, the Aspire CLI, and a running OCI container runtime, since the AppHost starts PostgreSQL, Redis and RabbitMQ as containers through `Aspire.Hosting.PostgreSQL`, `Aspire.Hosting.RabbitMQ` and `Aspire.Hosting.Redis` from `Directory.Packages.props`. `eShop.Web.slnf` is the solution filter the README builds and `.vscode/settings.json` already points `dotnet.defaultSolution` at it. The MAUI client under `src/ClientApp` needs workloads the server build does not, and `pr-validation-maui.yml` installs them separately.

It also reads how CI and the tests are set up, because the container should reproduce that. `pr-validation.yml` runs `actions/setup-dotnet` from `global.json`, `dotnet build eShop.Web.slnf` and `dotnet test --solution eShop.Web.slnf --no-build`; `playwright.yml` installs Node, runs `npm ci`, `npx playwright install --with-deps chromium` and `npm run test:e2e`, and `package.json` pins `@playwright/test` for the three specs under `e2e/`. `tests/` holds unit and functional projects for Basket, Catalog, Ordering and Webhooks plus `eShop.AppHost.UnitTests`, and the functional tests use the AppHost, so they need the container runtime too. There is no `.devcontainer/` directory; `.devcenter/catalog/definitions/imagedefinition.yaml` exists for Dev Box but holds only a placeholder line.

The agent writes `.devcontainer/devcontainer.json` on the `mcr.microsoft.com/devcontainers/base:ubuntu` image with features rather than a custom Dockerfile, so the pin lives in one readable file: `ghcr.io/devcontainers/features/dotnet:2` with `version` set to `10.0`, which the feature resolves against the `global.json` roll-forward, `ghcr.io/devcontainers/features/docker-in-docker:2` so the AppHost can start its containers inside the dev container, `ghcr.io/devcontainers/features/node:1` for Playwright, and `ghcr.io/devcontainers/features/github-cli:1`. A `postCreateCommand` runs `curl -sSL https://aspire.dev/install.sh | bash`, the install the Aspire docs give for Linux, then `dotnet restore eShop.Web.slnf` and `npm ci`; the MAUI workloads are left out on purpose and the file says so, since they are large and the README lists the client as optional. `customizations.vscode` carries the C# Dev Kit and Aspire extensions the README names and the `dotnet.defaultSolution` setting already in `.vscode`, and `forwardPorts` leaves the dashboard to Aspire's own port forwarding, which prints the dashboard URL with its login token.

Then it proves the container works the way CI does. The sandbox has no Docker, so the agent installs `docker.io` with apt, starts `dockerd`, installs the `@devcontainers/cli` package and runs `devcontainer up` on the repository, then `devcontainer exec` for `dotnet --version`, which must satisfy `global.json`, `aspire --version`, `dotnet build eShop.Web.slnf` and `dotnet test --solution eShop.Web.slnf --no-build`, the same two commands as `pr-validation.yml`. It starts the AppHost with `aspire start` inside the container to confirm docker-in-docker lets it create the PostgreSQL, Redis and RabbitMQ containers, checks `aspire ps`, and stops it. A README section under the IDE setup describes opening the folder in a container and what the first build downloads, and the pull request records the time the `postCreateCommand` took in the sandbox as a figure the reviewer can compare with their own machine.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "A Linear issue labelled agent says: \"New contributors spend a day installing things; give us a dev container that matches CI.\" Do the work in this .NET solution. Read global.json, the solution filters, Directory.Packages.props, the AppHost project and its config, every workflow under .github/workflows, package.json and the tests directory first, and list every tool a build and a test run need, including a container runtime if the app host starts containers. Write .devcontainer/devcontainer.json on the devcontainers base image using features for the .NET SDK at the pinned major, docker-in-docker when needed, Node when the repository has Playwright tests, and the GitHub CLI, with a postCreateCommand that installs any CLI the README requires and restores the solution. Add the editor extensions the README names. Leave optional workloads out and say why. The sandbox has no Docker: install docker.io, start dockerd, install the devcontainers CLI, bring the container up and run the same build and test commands CI runs inside it, and start and stop the app host to prove the runtime works. Add a README section. Open a pull request with the command output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request with `.devcontainer/devcontainer.json`, the README section and nothing else in the solution. Its description lists each feature with the version it pins and the prerequisite it replaces, the `postCreateCommand` steps, the output of `dotnet --version`, `aspire --version`, the build and the test run from inside the container, and the `aspire ps` listing that shows the AppHost's containers running under docker-in-docker; the full `devcontainer up` log is in the run's record.

A reviewer checks the SDK version the feature resolved against `global.json`, since a `rollForward` of `latestFeature` means the container may carry a newer patch than CI, and decides whether the MAUI workloads belong in a second configuration. The test output is the proof that the container matches `pr-validation.yml`; anything that passes in CI and not here is a missing tool, and the log says which.

## Run it on every Linear issue labelled agent

In the console, an automation with a `linear` trigger on `linear.issue.labeled` and the label `agent` starts one run per labelled issue, with the issue added after the prompt, in the Project's repository. Changes made by an app integration never fire it, so the agent's own comment on the issue does not start another run. Each run reads that solution's own `global.json` and workflows, so a solution on .NET 8 with no containers gets a smaller file without docker-in-docker.

From your own server, the same run is one `POST /o/{org}/sessions` per issue: put the repository in `resources` and add the issue's `https://linear.app/<workspace>/issue/<ID>` URL there too, so Rush reads it through your Linear connection into the prompt. A webhook URL on the API key reports `run.completed` or `run.failed` with the `session_url` when the turn finishes.

## Why run it on Rush?

A dev container is a claim that a fresh machine can build and test the solution, and the only way to check the claim is to build the container on a fresh machine and run the tests inside it. The agent does exactly that in its own sandbox, with Docker installed there for the purpose, and the pull request carries the version checks, the build and the test output from inside the container, so the reviewer sees the first contributor's experience before any contributor has it.

The same run fits any .NET solution, from a single web project to an Aspire app host with a dozen services, because it starts from `global.json` and the workflows rather than a template. Each solution gets the features its tools need and none it does not, and every run keeps the full record of the container build that proves it.

## Frequently asked questions

### Why features instead of a Dockerfile?

The features pin each tool with a version in one JSON file the whole team can read, and the devcontainers base image gets security updates without a rebuild step of your own. A Dockerfile is the right choice when a tool has no feature, and the agent switches to one in that case and says why.

### Does the Aspire app host work inside the container?

Yes, through the docker-in-docker feature, which gives the container its own Docker daemon so the app host can start PostgreSQL, Redis and RabbitMQ. The agent starts the app host inside the container during the run and the `aspire ps` output in the pull request shows those containers running.

### What about the MAUI client and its workloads?

They are left out, with a comment in the file. The README lists the client apps as optional and the workloads are large downloads most contributors never need; a second `devcontainer.json` under a subfolder can add them for the people who do.

### Will the SDK in the container match CI exactly?

It matches `global.json` the same way `actions/setup-dotnet` does: the feature installs the `10.0` channel and the roll-forward rule picks the patch. The pull request prints `dotnet --version` from inside the container so a reviewer can compare it with the CI log.

## More .NET jobs

- [Add a Dockerfile to a .NET Web App](https://getrush.ai/run/add-dockerfile/dotnet/)
- [Add a dotnet format Check to a .NET CI Workflow](https://getrush.ai/run/add-dotnet-format-check/dotnet/)
- [Add Feature Flags to a .NET API](https://getrush.ai/run/add-feature-flags/dotnet/)

## The same job on other stacks

- [Add a Dev Container to a Medusa Monorepo](https://getrush.ai/run/add-dev-containers/medusa/)
- [Add a Dev Container to a Docker Compose Project](https://getrush.ai/run/add-dev-containers/docker-compose/)

## More jobs like this: Turn a Linear label into a PR

- [Add Dialyzer to an Elixir App from a Linear Issue](https://getrush.ai/run/add-dialyzer/elixir/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
