Debugging .NET Core on Unix over SSH
With the release of Visual Studio 2017 RC3 it is now possible to attach to .NET Core processes running on Linux over SSH. This blog post will explain how to set this up.
On the Visual Studio computer, you need to install either the ‘ASP.NET and web development’ or the “.NET Core cross-platform development” workload in the 1/26/17 update for VS 2017 RC. If you previously installed Visual Studio 2017 RC, you can see if it is an RC3 release from Help->About.
On the Linux server, you need to install SSH server, unzip and either curl or wget. For example, on Ubuntu you can do that by running:
sudo apt-get install openssh-server unzip curl
Deploying the Application
In order to debug your application running on Linux, it will first need to be deployed there. One option for doing this is to copy sources to the target computer and build with ‘dotnet build’ on the Linux machine. Another option would be to build on Windows, and transfer the built artifacts (the application itself, any runtime libraries it might depend on and the .deps.json file).
For debugging, there are two important notes. First, it is much harder to debug retail-compiled code than debug-compiled code, so it is highly recommended to use the ‘Debug’ configuration. If you do need to use the ‘Release’ configuration, make sure to disable Tool->Options->Debugging->Just My Code. Second, the debugger for Linux will need to make sure Portable PDBs are enabled (which is the default), and they will need to be next to the dll.
Attaching the Debugger
Once the computers are configured and the application is up and running now we are ready to attach the debugger.
- Go to Debug->Attach to Process…
- In the ‘Connection Type’ drop down, select ‘SSH’
- Change the ‘Connection Target’ to the IP address or host name of the target computer
- Find the process that you would like to debug. By default, your code will run in a ‘dotnet’ process. You can look at the ‘Title’ column to see each processes command line arguments to find the process that you are interested in.
- Click ‘Attach’. You will get a dialog to select which type of code you would like to debug. Pick ‘Managed (.NET Core for Unix)’.
- Debug as you would expect
If you have any feedback we’d love to hear from you, send it from the VS Send Feedback feature or find us on twitter at @VS_Debugger.
Principal Software Engineerunzip curl