DEV Community

Debugging your .NET Core in Docker applications with VS Code

Aaron Powell on April 04, 2019

One of the nicest things about building applications of .NET Core is that its cross-platform support means that we can deploy our application as a ...
Collapse
 
teonivalois profile image
Teoni Valois

Excellent post, congratulations!

One thing that you didn't mention on your text, but could help others is that we need to map the source directory for a proper debug session by adding the sourceFileMap property in the launch.json file.

{
    "name": ".NET Core Docker Attach",
    "type": "coreclr",
    "request": "attach",
    "processId": "${command:pickRemoteProcess}",
    "pipeTransport": {
        "pipeProgram": "docker",
        "pipeArgs": ["exec", "-i", "sunshine-downloader"],
        "debuggerPath": "/vsdbg/vsdbg",
        "pipeCwd": "${workspaceRoot}",
        "quoteArgs": false
    },
    "sourceFileMap": {
        "/src": "${workspaceRoot}"
    }
}

In the example above I used a multi stage dockerfile, and the application was build on the /src folder. This causes the PDB files to reference such folder. By doing the sourceFileMap, we can translate the /src folder to our real source code directory.

This is what the OmniSharp docs says about it:

sourceFileMap: To debug programs built on computers other than the Visual Studio code computer, Visual Studio code needs to be hold how to map file paths. So, for example, if you are debugging 'ExampleProject' which was built in your home directory on the Linux server, and now you have the same code open in Visual Studio code, this rule tells the debugger to change any file paths that it sees in '/home/ExampleAccount/ExampleProject' and replace it with the open directory.

I just submitted a change to include it in the Wiki Page.

Collapse
 
aaronpowell profile image
Aaron Powell Microsoft Azure

Great tip!

Collapse
 
dawidkala profile image
dawidkala

I followed the instructions listed in this post but I'm not getting my breakpoints to work.

This is the error message I'm getting:

Breakpoint warning: No executable code of the debugger’s target code type is associated with this line.
Possible causes include conditional compilation, compiler optimizations, or the target architecture of this line is not supported by the current debugger code type.

What could I be doing wrong? Is there a full working example I could follow?

Collapse
 
glenmccallumcan profile image
Glen McCallum

This is a useful docker file. I've had hit and miss experience debugging .NET Core applications in docker from visual studio. But I hadn't taken the time to figure out the manual process.

Collapse
 
aaronpowell profile image
Aaron Powell Microsoft Azure

That was part of my motivation, the Visual Studio tooling can seem like a bunch of "magic" so I want to know what it's actually doing so that I can do it without Visual Studio if so desired.