Alt text: Purple background with white and yellow bold text reading “F5 Debugging .NET Apps in Containers with VS Code.” To the right are two white circular icons: the top one with “.NET” in purple, and the bottom one showing the Visual Studio Code logo.

⚠️ This blog post was created with the help of AI tools. Yes, I used a bit of magic from language models to organize my thoughts and automate the boring parts, but the geeky fun and the 🤖 in C# are 100% mine.

Hi!

I always forget how to do this, so I’ll write about it for future Bruno.

If you’ve ever fought with launch.json, tasks.json, volume mounts, vsdbg installs, and random port mappings… this one’s for you.

Here’s my quick ‘n dirty step-by-step to make it work.


1) Install the bits

  • Docker Desktop
  • VS Code extensions: Docker and C# / C# Dev Kit

Yes, you need these for VS Code to even think about attaching a debugger.


2) Let VS Code scaffold your stuff

Skip the “hand-craft JSON” step unless you love pain.
Hit Ctrl/Cmd+Shift+PContainers: Add Docker Files to Workspace… (or Containers: Initialize for container debugging if you already have a Dockerfile).

This will give you:

  • A proper Dockerfile
  • tasks.json with docker-build and docker-run: debug
  • launch.json with Containers: .NET Launch

3) Hit F5

Open the Run & Debug tab, select Containers: .NET Launch, press F5.
For .NET 7+, you can even build the container with the .NET SDK directly (no Dockerfile needed) when prompted.


4) Check ports & URLs

Make sure your app listens on 0.0.0.0 inside the container.
The common pattern is:

  • Expose port 8080 in the container
  • Map host port 5000:8080
  • Add ASPNETCORE_URLS=http://+:8080

5) Get the debugger in there

When VS Code asks to copy vsdbg into the container, say Yes.
You usually don’t need to mount your whole source tree for debugging — the tools take care of it.


6) Docker Compose?

Use Containers: Add Docker Compose Files to Workspace, then run Compose Up, and attach with Containers: .NET Attach (Preview).
Don’t try to launch a Compose setup with a normal launch.json — it’s an attach-only party.


7) When breakpoints don’t hit

The usual suspects:

  • You said “No” to copying vsdbg (re-attach, say Yes)
  • ASPNETCORE_URLS / ports are mismatched
  • You broke tasks.json / launch.json editing by hand
  • On macOS with odd errors like “dispatcher 80131534”, pin a known vsdbg version in your Dockerfile:
RUN apt-get update && apt-get install -y curl unzip \
    && curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v 17.0.10712.2 -l /remote_debugger


8) Sample configs (so you don’t start from scratch)

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Containers: .NET Launch",
      "type": "docker",
      "request": "launch",
      "preLaunchTask": "docker-run: debug",
      "netCore": {
        "appProject": "${workspaceFolder}/YourProject.csproj"
      }
    }
  ]
}

tasks.json (simplified idea — use the scaffolded ones)

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "docker-build",
      "label": "docker-build",
      "platform": "netCore",
      "dockerBuild": { "dockerfile": "Dockerfile", "tag": "yourapp:dev", "context": "." },
      "netCore": { "appProject": "${workspaceFolder}/YourProject.csproj" }
    },
    {
      "type": "docker-run",
      "label": "docker-run: debug",
      "dependsOn": [ "docker-build" ],
      "dockerRun": {
        "containerName": "yourapp",
        "ports": [ "5000:8080" ],
        "env": { "ASPNETCORE_URLS": "http://+:8080" }
      },
      "netCore": { "appProject": "${workspaceFolder}/YourProject.csproj", "enableDebugging": true }
    }
  ]
}


9) Big Visual Studio (the full IDE)

Right-click project → Add > Docker Support → set debug target to Docker → F5.
Visual Studio handles MSBuild, ports, and vsdbg without asking you twice.


10) Full docs and guides


💬 If you’ve got your own tips for debugging .NET in containers (especially for gnarly multi-container setups), drop them in the comments — I’ll happily steal them for the next update 😁

Happy coding!

Greetings

El Bruno

More posts in my blog ElBruno.com.

More info in https://beacons.ai/elbruno


One response to “🐋 F5 / Debug .NET Apps in Containers with Visual Studio Code and Visual Studio”

  1. […] 🐋 F5 / Debug .NET Apps in Containers with Visual Studio Code and Visual Studio (Bruno Capuano) […]

    Like

Leave a comment

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading