Visual Studio Linux Debugger

Visual Studio Linux Debugger

food man love people

The VS Linux Debugger is an open-source tool created to assist with remotely deploying and debugging your Linux applications from Visual Studio 2022. Check it out on the Microsoft Marketplace or GitHub.

To get started using it today it’s as easy as 1-2-3.. or perhaps, 2-3

Overview

Before getting started, it is recommended to ensure your system has the latest updates. These steps have been tested against Ubuntu 20.04 LTE and 22.04 LTE.

Though this project supports everywhere that .NET (Core) is supported, this section outlines steps for Ubuntu 22.04 LTE. It’s recommended to use the official Microsoft Install .NET on Linux guide.

If this is a new Ubuntu VM on Virtual Box, don’t forget to install the extensions $ sudo apt install virtualbox-ext-pack

Linux Configuration

Before getting started, make sure your system has the latest updates.

Linux Prerequisites

On your Linux machine install OpenSSH Server and cURL.

sudo apt update
sudo apt install openssh-server
sudo apt install curl

Now test your connection on Windows

ssh USERNAME@IPADDRESS

Install .NET 6

Run the following commands to add the Microsoft package signing key to your list of trusted keys.

wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

Next, install the SDK

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-6.0

For other .NET versions reference the table below

.NET VersionDotNet-SDK-XX.XX
6.0dotnet-sdk-6.0
5.0dotnet-sdk-5.0
3.1dotnet-sdk-3.0

Install the Extension

  1. Open Visual Studio
  2. Extensions > Manage Extensions
  3. Search for “VS Linux Debugger”
  4. Install and restart Visual Studio

Configure and Deploy

First, we’ll need to get the IP Address of the remote machine

Open a terminal and type, ifconfig, and copy the IP Address. In this example, 192.168.1.227. Please note, if you’re using a NAT connection on a VM it may appear as, 127.0.0.1. NAT and Bridged connections will be covered at a later time.

ifconfig

Next, we’re going to configure the Linux Debugger extension

  1. Visual Studio > Tools > Options
  2. Select, “Linux Debugger” from the treeview
  3. Input the IP Address
  4. Input the User Name
  5. Input the Password
  6. Click, OK
Tools Options – Linux Debugger

Deploy and Debug

Now you’re ready to deploy and debug your applications! We’ll begin by making a new .NET 6 Console application.

Console.WriteLine("Hello .NET 6, VS Linux Debugger!");

Console.WriteLine("Apply breakpoint here!");

Console.WriteLine("All done!");

Console Debugging

After setting your breakpoint in the sample, you can now Deploy and Debug!

  1. Visual Studio > Extensions > Linux Debugger
  2. Select, Build, Deploy and Debug.

GUI Debugging

To debug Linux GUI applications debugging, I’m currently working on a solution for that. For now, you can still use Build and Deploy followed by manually attaching to the process in Visual Studio to debug it.

  1. VS: Linux Debugger > Build and Deploy
  2. Run the app on the remote machine via, “dotnet MyApp.dll
  3. VS: Debug > “Attach to Process…
  4. Connection Type to, SSH
  5. Connection Target: “UserName@IPADDRESS”

Bonus: Output Window

You can monitor and debug the commands sent to your remote device via the Output window’s Linux Debugger output

Output Window – Linux Debugger