Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

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.

C# (.NET)

Summary

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.

Using this definition

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 (or 3.1-bullseye, 3.1-focal to pin to an OS version)
  • mcr.microsoft.com/vscode/devcontainers/dotnet:6.0 (or 6.0-bullseye, 6.0-focal to 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.1
  • mcr.microsoft.com/vscode/devcontainers/dotnet:0.202-3.1
  • mcr.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.

Debug Configuration

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"

Enabling HTTPS in ASP.NET using your own dev certificate

To enable HTTPS in ASP.NET, you can mount an exported copy of your local dev certificate.

  1. 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"
  2. 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",
    }
  3. Finally, make the certificate available in the container as follows:

    If using GitHub Codespaces and/or Remote - Containers

    1. Start the container/codespace
    2. Drag ~/.aspnet/https/aspnetapp.pfx from your local machine into the root of the File Explorer in VS Code.
    3. 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.

Installing Node.js or the Azure CLI

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.

"args": {
    "VARIANT": "3.1",
    "NODE_VERSION": "14" // Set to "none" to skip Node.js installation
}

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.

Adding the definition to your folder

  1. 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.

  2. To use the pre-built image:

    1. Start VS Code and open your project folder or connect to a codespace.
    2. Press F1 select and Add Development Container Configuration Files... command for Remote-Containers or Codespaces.
    3. Select this definition. You may also need to select Show All Definitions... for it to appear.
  3. To build a custom version of the image instead:

    1. Clone this repository locally.
    2. Start VS Code and open your project folder or connect to a codespace.
    3. Use your local operating system's file explorer to drag-and-drop the locally cloned copy of the .devcontainer folder for this definition into the VS Code file explorer for your opened project or codespace.
    4. Update .devcontainer/devcontainer.json to reference "dockerfile": "base.Dockerfile".
  4. After following step 2 or 3, the contents of the .devcontainer folder in your project can be adapted to meet your needs.

  5. Finally, press F1 and run Remote-Containers: Reopen Folder in Container or Codespaces: Rebuild Container to start using the definition.

Testing the definition

This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps:

  1. If this is your first time using a development container, please follow the getting started steps to set up your machine.
  2. Clone this repository.
  3. Start VS Code, press F1, and select Remote-Containers: Open Folder in Container...
  4. Select the containers/dotnet folder.
  5. After the folder has opened in the container, if prompted to restore packages in a notification, click "Restore".
  6. After packages are restored, press F5 to start the project.
  7. 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.
  8. You should see "Hello remote world from ASP.NET!" after the page loads.
  9. From here, you can add breakpoints or edit the contents of the test-project folder to do further testing.

License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License. See LICENSE.