SuessLabs / VsLinuxDebug

VS Extension to remotely deploy and debug your .NET (Core) C# solutions directly to your Linux or Raspberry Pi devices! .NET Core 3.1, .NET 5, 6, 7, 8, 9
https://marketplace.visualstudio.com/items?itemName=SuessLabs.VSLinuxDebugger
MIT License
37 stars 8 forks source link
csharp debugger deploy dotnet linux net netcore netcore31 raspberry-pi raspberrypi remote ssh suesslabs visual-studio visual-studio-extension xeno-innovations

VS .NET Linux Debugger

Remotely deploy and debug your .NET C# apps via SSH to Linux using Visual Studio 2022.

Get it on the VS MarketPlace!

Visual Studio's "attach to process via SSH" is cute, but it lacks deployment and automatic attaching. This project allows you to do just that on your Linux VM or Raspberry Pi over the network!

Suess Labs consulting is sponsored by Xeno Innovations, Inc.

Overview

Now developers can build, deploy and debug projects on their remote Linux (Ubuntu, Raspberry PI, etc) devices! Customize your SSH connection to use either a password or a private key.

If you enjoy using the extension, please give it a ★★★★★ rating on the Visual Studio Marketplace.

Supported Remote OS

The following Linux distrobutions have been validated and are supported.

Usage

VS Menu

For GUI app debugging, you can use the Build and Deploy feature, however, you must manually Attach to Process via SSH using Visual Studio at this time.

Getting Started

Linux, we'll need SSH and cURL for access and downloading any missing tools:

sudo apt install openssh-server
sudo apt install curl

Windows:

  1. Open Visual Studio (VS) > Tools > Options > Linux Debugger
  2. Input: Remote Host IP address
  3. Input: Remote's User Name and Password
  4. VS > Extensions > Linux Debugger > Build, Deploy, Debug

Tools Options

Manually Attaching (for GUI apps)

For GUI projects, you can use Build and Deploy and then manually attach to the process via SSH by using Visual Studio's built-in tool

  1. Deploy to remote machine via
    1. Extensions > Linux Debugger > "Build and Deploy"
  2. Run GUI app on remote machine
    1. dotnet MyGuiApp.dll
  3. Debug > "Attach to Process.."
  4. Connection Type: SSH
  5. Connection Target: (Remote machine's IP)
  6. (Select process)
  7. Click, Attach
  8. Check, "Managed (.NET Core for Unix)"
  9. Click, OK

This will save you 1.5 minutes on every build of manual uploading and updating rights via chown -R.

Manually Attaching (for Command line apps)

For CLI projects, you can use Build and Deploy and then manually attach to the process via SSH by using Visual Studio's built-in tool (similar to above).

You may have to manually interrupt your app via Console.ReadLine(); high-up in your entry-point (i.e. main()).

  1. Deploy to remote machine via
    1. Extensions > Linux Debugger > "Build and Deploy"
  2. Run your CLI app on remote machine
    1. dotnet MyCliApp.dll
  3. Debug > "Attach to Process.."
    1. Connection Type: SSH
    2. Connection Target: (Remote machine's IP)
    3. (Select process)
    4. Click, Attach
    5. Check, "Managed (.NET Core for Unix)"
    6. Click, OK
  4. Continue your application, if using a manual interrupt (i.e. Console.ReadLine();)

This will save you 1.5 minutes on every build of manual uploading and updating rights via chown -R.

How To Generate Private Key (optional)

The following steps are options if you wish to use an SSH Private Key. These steps were written for Windows 10, however, on Linux the steps are similar.

  1. Open PowerShell:
  2. Generate key (with old PEM format)
    1. ssh-keygen -m PEM -t rsa -b 4096
    2. In the future, we'll be able to use ssh-keygen.. just not yet.
  3. Set output name (default is okay for basic setups)
  4. Input a passphrase for the key (OPTIONAL)
  5. Windows will now generate your RSA public/private key pair.
    1. Default location: %UserProfile%\.ssh (WINOWS)
    2. The public key will be stored as id_rsa.pub in the directory
  6. Upload the public key to your remote machine
    1. Navigate to folder, ~/.ssh/ on Linux device
    2. If ~/.ssh/authorized_keys exists, append the contents of id_rsa.pub to the next line.
    3. If it does not exist, simply upload id_rsa.pub and rename it to, authorized_keys
  7. DONE!

Future Features

Developers Wanted

Contributors and Q/A are welcomed!

To contribute, please pick off an item from the project or issue page. We'd love to hear your enhancement ideas as well.

References

Copyright 2024 Xeno Innovations, Inc.