[C#, VS Code]
Today we will setup an environment where we can develop and debug code remotely on a Linux environment.
This is useful for a number of reasons:
- The remote machine is a server environment (that is to say, there is no UI component)
- You do not have physical access to the environment
- You want to use your local IDE, environment and configuration.
On the machine you want to develop on, setup a SSH client.
1 - Setup SSH Client
|Windows 10 1803+ / Server 2016/2019 1803+||Install the Windows OpenSSH Client|
|Earlier Windows||Install Git for Windows|
|RHEL / Fedora / CentOS||Run
2 - Install Visual Studio Code
If you haven’t already, install Visual Studio Code. The easiest way is through chocolatey
choco install vscode
3 - Install The Remote Development Pack
Once installed you should see this in the extensions pane
On the machine you want the code to run on, setup a SSH server, if you do not already have one.
If you are using Debian, or a Debian based Linux you can check with this command
dpkg -s openssh-server | grep Status
You should get a response like this if it is installed
If it’s not installed, here are the steps for your OS
|Debian 8+ / Ubuntu 16.04+||Run
|RHEL / CentOS 7+||Run
|SuSE 12+ / openSUSE 42.3+||In Yast, go to Services Manager, select “sshd” in the list, and click Enable. Next go to Firewall, select the Permanent configuration, and under services check sshd.|
|Windows 10 1803+ / Server 2016/2019 1803+||Install the Windows OpenSSH Server|
|macOS 10.14+ (Mojave)||Enable Remote Login|
Once that is setup now we can attempt a connection.
For the rest of this example, I will be connecting to a remote Ubuntu box.
Ctrl + P to open the command bar. Type
remote-ssh into the command.
As it filters,
select connect to host
Given we have never connected before, we will get a prompt to configure the remote host.
Here we choose
Add New SSH Host
You’ll get this prompt:
Here you key in the command to access the remote machine.
In my case, that is
Next you will be asked where to save the config. I believe it should not matter which you choose.
You should get a prompt to choose the remote server type - Linux, Windows or OSX. I chose Linux.
You should get this confirmation.
Finally you should see this:
Go ahead and click
Connect. You should see this prompt as VS Code remotely sets up the infrastructure it needs to work its magic.
Finally if all goes well you should get the main screen of VS Code.
The next thing is to create a new project.
Open a terminal as follows:
You can also use the shortcut
Ctrl + Shift + `
This should give you a terminal on the machine you are connected to, not locally.
We can then go on and create a new project.
dotnet new console -o Hello
This creates a console project and places it in the folder
Finally we can open this project. Click
You should get the following prompt. Not that the file system displayed is the remote file system.
Here you browse to the location of the project just created.
If all went well, the project should open.
You may also see VS Code configuring the C# plugin.
Next let us run the project.
Run. Alternatively, press
In the debug window we should see status messages from the debugger and finally our output.
To prove that the debugger works, we set a breakpoint in our code by clicking in the margin.
If we now run the debugger again, VS Code will stop execution at the breakpoint.
And there you have it. You can now remotely create, develop and debug applications from your primary machine.
You can always tell where you are connected on the status bar of VS Code.