IMPORTANT NOTE: We're starting to migrate contents of this repo to the devcontainers org, as part of the work on the open dev container specification.
We'll now be publishing the dotnet image from devcontainers/images/src/dotnet.
For more details, you can review the announcement issue.
Develop C# and .NET based applications. Includes all needed SDKs, extensions, and dependencies.
| Metadata | Value |
|---|---|
| Contributors | The VS Code Team |
| Categories | Core, Languages |
| Definition type | Dockerfile |
| Published images | mcr.microsoft.com/vscode/devcontainers/dotnet |
| Available image variants | 3.1 / 3.1-focal / 6.0 /6.0-bullseye, 6.0-focal, 3.1-bullseye (full list) |
| Published image architecture(s) | x86-64, arm64/aarch64 for bullseye variants |
| Works in Codespaces | Yes |
| Container host OS support | Linux, macOS, Windows |
| Container OS | Ubuntu (-focal), Debian (-bullseye) |
| Languages, platforms | .NET, .NET Core, C# |
See history for information on the contents of published images.
While this definition should work unmodified, you can select the version of .NET / .NET Core the container uses by updating the VARIANT arg in the included devcontainer.json (and rebuilding if you've already created the container).
// Or you can use 3.1-bullseye or 3.1-focal if you want to pin to an OS version
"args": { "VARIANT": "3.1" }Note that .NET 6.0 has switched its default OS to Debian 12 / bullseye. We also offer a 6.0-focal image if you would prefer to use Ubuntu 20.04 / Focal.
You can also directly reference pre-built versions of .devcontainer/base.Dockerfile by using the image property in .devcontainer/devcontainer.json or updating the FROM statement in your own Dockerfile to one of the following. An example Dockerfile is included in this repository.
mcr.microsoft.com/vscode/devcontainers/dotnet(latest)mcr.microsoft.com/vscode/devcontainers/dotnet:3.1(or3.1-bullseye,3.1-focalto pin to an OS version)mcr.microsoft.com/vscode/devcontainers/dotnet:6.0(or6.0-bullseye,6.0-focalto pin to an OS version)
You can decide how often you want updates by referencing a semantic version of each image. For example:
mcr.microsoft.com/vscode/devcontainers/dotnet:0-3.1mcr.microsoft.com/vscode/devcontainers/dotnet:0.202-3.1mcr.microsoft.com/vscode/devcontainers/dotnet:0.202.0-3.1
See history for information on the contents of each version and here for a complete list of available tags.
Alternatively, you can use the contents of base.Dockerfile to fully customize your container's contents or to build it for a container host architecture not supported by the image.
Only the integrated terminal is supported by the Remote - Containers extension. You may need to modify your .vscode/launch.json configurations to include the following:
"console": "integratedTerminal"To enable HTTPS in ASP.NET, you can mount an exported copy of your local dev certificate.
-
Export it using the following command:
Windows PowerShell
dotnet dev-certs https --trust; dotnet dev-certs https -ep "$env:USERPROFILE/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
macOS/Linux terminal
dotnet dev-certs https --trust; dotnet dev-certs https -ep "${HOME}/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere"
-
Add the following in to
.devcontainer/devcontainer.json:"remoteEnv": { "ASPNETCORE_Kestrel__Certificates__Default__Password": "SecurePwdGoesHere", "ASPNETCORE_Kestrel__Certificates__Default__Path": "/home/vscode/.aspnet/https/aspnetapp.pfx", }
-
Finally, make the certificate available in the container as follows:
If using GitHub Codespaces and/or Remote - Containers
- Start the container/codespace
- Drag
~/.aspnet/https/aspnetapp.pfxfrom your local machine into the root of the File Explorer in VS Code. - Open a terminal in VS Code and run:
mkdir -p /home/vscode/.aspnet/https && mv aspnetapp.pfx /home/vscode/.aspnet/https
If using only Remote - Containers with a local container
Add the following to
.devcontainer/devcontainer.json:"mounts": [ "source=${env:HOME}${env:USERPROFILE}/.aspnet/https,target=/home/vscode/.aspnet/https,type=bind" ]
If you've already opened your folder in a container, rebuild the container using the Remote-Containers: Rebuild Container command from the Command Palette (F1) so the settings take effect.
Given JavaScript front-end web client code written for use in conjunction with an ASP.NET back-end often requires the use of Node.js-based utilities to build, this container also includes nvm so that you can easily install Node.js. You can change the version of Node.js installed or disable its installation by updating the args property in .devcontainer/devcontainer.json.
If you would like to install the Azure CLI, you can reference a dev container feature by adding the following to .devcontainer/devcontainer.json:
{
"features": {
"azure-cli": "latest"
}
}If you've already opened your folder in a container, rebuild the container using the Remote-Containers: Rebuild Container command from the Command Palette (F1) so the settings take effect.
-
If this is your first time using a development container, please see getting started information on setting up Remote-Containers or creating a codespace using GitHub Codespaces.
-
To use the pre-built image:
- Start VS Code and open your project folder or connect to a codespace.
- Press F1 select and Add Development Container Configuration Files... command for Remote-Containers or Codespaces.
- Select this definition. You may also need to select Show All Definitions... for it to appear.
-
To build a custom version of the image instead:
- Clone this repository locally.
- Start VS Code and open your project folder or connect to a codespace.
- Use your local operating system's file explorer to drag-and-drop the locally cloned copy of the
.devcontainerfolder for this definition into the VS Code file explorer for your opened project or codespace. - Update
.devcontainer/devcontainer.jsonto reference"dockerfile": "base.Dockerfile".
-
After following step 2 or 3, the contents of the
.devcontainerfolder in your project can be adapted to meet your needs. -
Finally, press F1 and run Remote-Containers: Reopen Folder in Container or Codespaces: Rebuild Container to start using the definition.
This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps:
- If this is your first time using a development container, please follow the getting started steps to set up your machine.
- Clone this repository.
- Start VS Code, press F1, and select Remote-Containers: Open Folder in Container...
- Select the
containers/dotnetfolder. - After the folder has opened in the container, if prompted to restore packages in a notification, click "Restore".
- After packages are restored, press F5 to start the project.
- Once the project is running, open your browser to http://0.0.0.0:8090. Or, in the Debug Console view, select the "http://0.0.0.0:8090" link.
- You should see "Hello remote world from ASP.NET!" after the page loads.
- From here, you can add breakpoints or edit the contents of the
test-projectfolder to do further testing.
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. See LICENSE.