Debugging .NET Core on Unix over SSH

aman_satveerraj

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.

Machine Setup

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.

  1. Go to Debug->Attach to Process…
  2. In the ‘Connection Type’ drop down, select ‘SSH’
  3. Change the ‘Connection Target’ to the IP address or host name of the target computer
  4. 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. Attach to process dialog showing a list of process from a remote Linux machine over an SSH transport.
  5. Click ‘Attach’. You will get a dialog to select which type of code you would like to debug. Pick ‘Managed (.NET Core for Unix)’.
  6. Debug as you would expect

A picture showing Visual Studio stopped at a breakpoint hit in code running on a remote Linuc machine.

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.

Gregg Miskelly Principal Software Engineerunzip curl

0 comments

Discussion is closed.

Feedback usabilla icon