Debug .NET Core within a container

Prerequisites

  1. Install the .NET Core SDK, which includes support for attaching to the .NET Core debugger.

  2. Install the Visual Studio Code C# extension, which includes support for attaching to the .NET Core debugger with VS Code.

  3. macOS users only: Add /usr/local/share/dotnet/sdk/NuGetFallbackFolder as a shared folder in your Docker preferences.

    dockerSharedFolders

Walkthrough

  1. If needed, create a .NET Core project with dotnet new.
  2. Open the project folder in VS Code.
  3. Wait until a notification appears asking if you want to add required assets for debugging. Click Yes:

csharpPrompt

  1. Open the Command Palette (kb(workbench.action.showCommands)) and enter Docker: Add Docker Files to Workspace.... If you have already dockerized your app, you can instead do Docker: Initialize for Docker debugging. Follow the prompts.
  2. Switch to the Run view (kb(workbench.view.debug)).
  3. Select the Docker .NET Core Launch launch configuration.
  4. Optionally, set a breakpoint.
  5. Start debugging! (kb(workbench.action.debug.start))

For additional customization options, see the documentation on Tasks and Debug containerized apps.