简体   繁体   中英

How do I attach VS Code debugger to a .NET Core watch process running in docker container

I have a .NET Core app running inside a Docker container as part of a compose configuration. The app is run using dotnet watch run. I have made the following launch configuration in launch.json:

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

When i run the debug task, the process picker appears. However, i cant seem to seleck any of the processes that apear. The list of available process include:

dotnet 1 dotnet watrch run
dotnet <defunct> 216
dotnet <defunct> 71
...

I would like to think that the first one is the correct one to select. If i select it, I receive the error: The pipe program 'docker' exited unexpectedly with code 126.

Does anyone have any experience with this and know what i might be doing wrong?

It looks like dotnet watch spawns several other processes for file watching, rebuilding your assembly, and finally rerunning your built assembly. You have to attach to the child process that actually runs that built assembly. It should look something like the following:

dotnet exec yourapp.dll

where yourapp.dll is the assembly built by the project that's being watched. For reference, these were the processes leading down to the assembly I had to attach to (the first is my docker entrypoint shell script and foo.csproj outputs MyApp.dll):

bin/sh -c /bin/bash ./entrypoint.sh
dotnet watch -p foo/foo.csproj run
/usr/share/dotnet/dotnet /usr/share/dotnet/sdk/2.2.401/DotnetTools/dotnet-watch/2.2.0/tools/netcoreapp2.2/any/dotnet-watch.dll -p foo/foo.csproj run
/usr/share/dotnet/dotnet run
dot`net exec /app/foo/MyApp.dll

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM