DEV Community

Discussion on: Debugging your .NET Core in Docker applications with VS Code

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!