Scott Hanselman

Visual Studio Code Remote Development over SSH to a Raspberry Pi is butter

June 11, '19 Comments [12] Posted in Hardware | Open Source | Python
Sponsored By

There's been a lot of folks, myself included, who have tried to install VS Code on the Raspberry Pi. In fact, there's a lovely process for this now. However, we have to ask ourselves is a Raspberry Pi really powerful enough to be running a full development environment and the app being debugged? Perhaps, but maybe this is a job for remote debugging. That means installing Visual Studio Code locally on my Windows or Mac machine, then having Visual Studio code install its headless server component (for ARM7) on the Pi.

In January I blogged about Remote Debugging with VS Code on a Raspberry Pi using .NET Core on ARM. It was, and is, a little hacked together with SSH and wishes. Let's set up a proper VS Code Remote environment so I can be productive on a Pi while still enjoying my main laptop's abilities.

  • First, can you ssh into your Raspberry Pi without a password prompt?
    • If not, be sure to set that up with OpenSSH, which is now installed on Windows 10 by default.
    • You know you've got it down when you can "ssh pi@mypi" and it just drops you into a remote prompt.
  • Next, get Visual Studio Code Insiders plus

From within VS Code Insiders, hit Ctrl/CMD+P and type "Remote-SSH" for some of the choices.

Remote-SSH options in VS Code

I can connect to Host and VS Code will SSH into the PI and install the VS Code server components in ~./vscode-server-insiders and then connect to them. It will take a minute as its downloading a 25 meg GZip and unzipping it into this temp folder. You'll know you're connected when you see this green badge as seen below that says "SSH: hostname."

Green badge in VS Code - SSH: crowpi

Then when you go "File | Open Folder" from the main menu, you'll get the remote system's files! You are working and editing locally on remote files.

My Raspberry Pi's desktop, remotely

Note here that some of the extensions are NOT installed locally! The Python language services (using Jedi) are running remotely on the Raspberry Pi, so when I get intellisense, I'm getting it remoted from the actual machine I'm developing on, not a guess from my local box.

Some extentions are local and others are remote

When I open a Terminal with Ctrl+~, see that I'm automatically getting a remote terminal and I've even running htop in it!

Check this out, I'm doing a remote interactive debugging session against CrowPi samples running on the Raspberry Pi (in Python 2) remotely from VS Code on my Windows 10 machine! I did need to make one change to the remote settings as it was defaulting to Python3 and I wanted to use Python2 for these samples.

Remote Debugging a Raspberry Pi

This has been a very smooth process and I remain super impressed with the VS Remote Development experience. I'll be looking at containers, and remote WSL debugging soon as well. Next step is to try C#, remotely, which will mean making sure the C# OmniSharp Extension works on ARM and remotely.


Sponsor: Suffering from a lack of clarity around software bugs? Give your customers the experience they deserve and expect with error monitoring from Raygun.com. Installs in minutes, try it today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Wednesday, June 12, 2019 2:06:15 AM UTC
Unsupported architecture: armv6l


on a Raspberry Pi Zero W
Josh
Wednesday, June 12, 2019 7:28:35 AM UTC
Amazing!
Daniel
Wednesday, June 12, 2019 9:45:18 AM UTC
And how to do it with Visual Studio 2019?
Icke
Wednesday, June 12, 2019 2:57:32 PM UTC
That is awesome Scott, are you running a flavor of Linux in your Pi or Windows IOT Core?
Paulo Godinho
Wednesday, June 12, 2019 4:32:24 PM UTC
@Paulo - presumably it's Raspbian. It's unlikely to be Windows IOT Core as you ask, because the file structures in the screenshots are Linux style and he runs htop (which is Linux plus the screenshot again confirms things like a user "root" which isn't typical on Windows)

It does look pretty cool
Neil Stoker
Friday, June 14, 2019 5:22:27 PM UTC
Nice!!!! Working with a Pi 2 Model B (Raspbian) from MacOS High Sierra with debug function tested. At least in the first tryouts worked fine.
Armando Baños Pascual
Saturday, June 15, 2019 3:33:24 PM UTC
Very cool, Scott - thanks for sharing! This blew my 9yo son's mind! :)

It took me a bit of time to get this up and running, so thought I'd share a couple of things I learned along the way. This was my first experience with SSH keys, so there may be better ways I didn't find or know about.

While 'ssh-keygen -t rsa' works natively on Windows, there isn't a Windows equivalent 'ssh-copy-id' that I could find.
The way I found easiest to get the public key to the Pi was to:
- Open the key file 'c:\users\<user>\.ssh\id_rsa.pub' in notepad and copy the line without including any spaces.
- SSH into the Pi by using "ssh <user>@<host>"
- Traversing to the ssh directory "cd ~/.ssh"
- Opening the authorized_keys file using "sudo nano authorized_keys"
- Pasting the line from the Windows .pub file (on the clipboard) and saving it.
- At this point, you should be able to disconnect from the Pi, and reconnect without being prompted for credentials.

I'll note that I tried using a different .pub file name, but when I tried to connect to the Pi from VSCode, it didn't seem to like the -i to specify the alternate key file. I needed to revert back to id_rsa (which is the default for ssh-keygen when you don't specify a filename).

It wasn't completely obvious to me that Remote-SSH got installed when the Remote Development extension was installed in VSCode. Just uninstall the auto-installed "Remote-SSH" and install the "Remote-SSH (Nightly)" and you should be good to go.

I know this got a bit long, but thought it might help others ...
Mark McConnell
Sunday, June 16, 2019 6:23:32 PM UTC
Is there a way to get C# debugging working? I get an error about armv7h not being supported.

This seems strange given vsdbg can install fine by itself?
sam
Monday, June 17, 2019 7:08:21 PM UTC
Why do we need nightly instead of stable ? Any special feature needed ?
Frank
Wednesday, June 19, 2019 3:45:04 AM UTC
Im spinning my wheels here and finding nothing that works in any forums. Has anyone encountered these errors on Remote-SSH: Connect to Host?


> Installing to /home/pi/.vscode-server/bin/c7d83e57cd18f18026a8162d042843bda1bcf2
> 1f...
> Downloading with wget
>
> https://update.code.visualstudio.com/commit:c7d83e57cd18f18026a8162d042843bda1bc
> f21f/server-linux-armhf/stable:
> 2019-06-18 22:39:40 ERROR 404: Not Found.

...

"install" terminal command done
Received install output: 489a5c10-020c-48c9-9639-62c27181d810##25##
Server download failed
Downloading VS Code Server failed. Please try again later.
Jeff
Thursday, June 20, 2019 12:46:32 AM UTC
I came across your blog post while seeking the best way to code on a Raspbery PI, for people with a Visual Studio background.

Maybe you and your readers already knew this, but I just discovered that Visual Studio itself (not Visual Studio Code) has a template for coding C++ against Raspberry PI, and the documentation says it supports remote debugging. The documentation also indicates it handles connecting to the remote board automatically within Visual Studio.

Not sure if it matters, but

  • I have Visual Studio 2019 Community (free)

  • I ran the Visual Studio updater to get C++ for Linux templates

  • .. And one of the templates I received was for a Raspberry PI blink application (4 lines of code and wiringPI.h)


I haven't tried it out yet, but it looks like I don't need to install .NET Core on the Raspberry PI, so that simplifies things.

This is great for me, since it looks like I can keep working in an environment I already know and love, and don't need to learn Python.
Friday, June 21, 2019 2:53:21 PM UTC

> Jeff Wrote:
> https://update.code.visualstudio.com/commit:c7d83e57cd18f18026a8162d042843bda1bc
> f21f/server-linux-armhf/stable:
> 2019-06-18 22:39:40 ERROR 404: Not Found.


Jeff, you need to use Visual Studio Code Insiders. I got the same error when using the standard version.
Jean-Claude Viau
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.