Debug .NET Core within a container
Prerequisites
-
Install the .NET Core SDK, which includes support for attaching to the .NET Core debugger.
-
Install the Visual Studio Code C# extension, which includes support for attaching to the .NET Core debugger with VS Code.
-
macOS users only: Add
/usr/local/share/dotnet/sdk/NuGetFallbackFolder
as a shared folder in your Docker preferences.
Walkthrough
-
If needed, create a .NET Core project with
dotnet new
. -
Open the project folder in VS Code.
-
Wait until a notification appears asking if you want to add required assets for debugging. Click Yes:
-
Open the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) 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.
-
Switch to the Run view (⇧⌘D (Windows, Linux Ctrl+Shift+D)).
-
Select the Docker .NET Core Launch launch configuration.
-
Optionally, set a breakpoint.
-
Start debugging! (F5)
For additional customization options, see the documentation on Tasks and Debug containerized apps.