How to Debug Inside a .NET Container with VS Code?

Josef Gabrielsson
1 min readNov 15, 2024

Debugging containerized .NET applications can be tricky, but VS Code makes it straightforward with tasks.json and launch.json. By configuring these files, you can automate setup steps like installing debugging tools and seamlessly attach the VS Code debugger to your running container.

tasks.json: Automating Debug Tool Installation

The tasks.json file allows you to automate essential setup tasks for debugging. Below is an example task for installing the vsdbg debugging tool inside your .NET container:

{
"version": "2.0.0",
"tasks": [
{
"label": "Install vsdbg in Docker Container",
"type": "shell",
"command": "docker",
"args": [
"exec",
"-i",
"your_container",
"sh",
"-c",
"test -f /vsdbg/vsdbg || (apt update && apt install curl -y && curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /vsdbg)"
],
"problemMatcher": [],
"group": "build"
}
]
}

launch.json: Attaching the Debugger

The launch.json file defines how to connect the VS Code debugger to your running container. Below is an example configuration:

{
"version": "0.2.0",
"configurations": [
{
"name": "Docker .NET Core Attach - your_container",
"type": "coreclr",
"request": "attach",
"preLaunchTask": "Install vsdbg in Docker Container",
"processId": 1,
"sourceFileMap": {
"/app": "${workspaceFolder}"
},
"pipeTransport": {
"pipeProgram": "docker",
"pipeArgs": [
"exec",
"-i",
"your_container"
],
"debuggerPath": "/vsdbg/vsdbg",
"pipeCwd": "${workspaceFolder}",
"quoteArgs": false
}
}
]
}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response