skip to Main Content

I have a C# .NET CORE console application running in a Docker container, which runs in WSL2 Ubuntu 20.04.

Now I would like to use Visual Studio (in Windows) to debug that C# console app running in that Docker container.

How can I do it in Visual Studio?
I have tried using the method suggested in here, but unsuccessful when I tried to connect to Remote System

enter image description here

Can anyone point me how to debug C# code by attaching to a process running in a Docker container hosted in WSL2?

2

Answers


    1. Make sure your container is running.
    2. Select Debug > Attach process(Make sure "Show processes for all users" is checked)
      Attach to Process
      2.1 Connection type: Windows Subsystem for Linux (WSL)
      2.2 Connection target: your distro name
      2.3 Attach to: Managed (.NET Core for Unix) code
    3. Navigate to "dotnet" process, your application should be there
    Login or Signup to reply.
  1. The attach to process dialog now supports connecting to a process in a container: https://learn.microsoft.com/en-us/visualstudio/debugger/attach-to-process-running-in-docker-container?view=vs-2022#attach-to-a-process-running-on-a-linux-docker-container
    enter image description here

    Also, when the container is running through the local Docker Desktop you can start the attach to a process dialog from the Containers window in VS: https://learn.microsoft.com/en-us/visualstudio/containers/view-and-diagnose-containers?view=vs-2022#attach-the-debugger-to-a-process
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search