Search code examples
dockervisual-studiovisual-studio-2019

How to debug a Docker container using Visual Studio without an internet connection


I need to debug an application running inside a Windows Docker container using Visual Studio (I have 2019 but can get 2022 if needed). I need to do this in an environment that is not connected to the internet, and visual studio does not seem happy with this. Whever I attempt to select my container in the "Attach to Process" dialog the output window in Visual Studio shows the following:

Downloading debugger package... Command 'docker exec -i container_name "C:\Windows\System32\curl.exe" -sSL "https://aka.ms/vs/16/release/16.5/debugger/OneCore.Msvsmon.amd64.enu.zip" -w "%{content_type}" -o "c:.vs-debugger\OneCore.Msvsmon.amd64.enu.zip"' failed with code '0x6'.

My understanding is that VS is attempting to install something into my container for debugging purposes, but it can't access what it wants to install.

I can get whatever files are needed transferred onto the target system by request. Is there a way for me to manually install what VS needs for debugging into the container such that it will be able to debug without an internet connection?

I have tried to copy the .zip file mentioned directly into the container at C:.vs-debugger. I have also tried extracting the contents to that location. In both cases VS still logs the error shown above and fails to connect to the container.


Solution

  • For Windows Containers, there is no way for Visual Studio to support attach without an internet connection.

    Two possible work arounds:

    1. Launch under a debugger instead of attaching - if your scenario is something that is supported by Visual Studio's Docker tools and you can run the container locally, you could launch your project under the debugger.
    2. Manually deploy and start the remote debugger (msvsmon.exe), and then connect using the 'Windows (No Authentication)' transport.

    Here are some basic instructions for #2:

    1. Setup your Docker file to -

      • Download the version of msvsmon they want from the https://aka.ms link and extract it
      • Open a port that you will run msvsmon on, be careful to only export this port to the computer running Visual Studio
    2. docker exec in and start msvsmon (ex: msvsmon.exe /port /noauth /nosecuritywarn /anyuser /timeout )

    3. If not running the container locally, setup port forwarding

    4. Connect from Visual Studio using the ‘No Authentication’ transport