{"id":2576,"date":"2021-01-31T09:21:08","date_gmt":"2021-01-31T09:21:08","guid":{"rendered":"https:\/\/wordpress-634681-2064240.cloudwaysapps.com\/?p=2576"},"modified":"2023-01-23T09:39:19","modified_gmt":"2023-01-23T09:39:19","slug":"deploying-and-debugging-raspberry-pi-net-applications-using-vs-code","status":"publish","type":"post","link":"https:\/\/www.petecodes.co.uk\/deploying-and-debugging-raspberry-pi-net-applications-using-vs-code\/","title":{"rendered":"Deploying and Debugging Raspberry Pi .NET Applications using VS Code"},"content":{"rendered":"\n
Historically, debugging embedded applications is hard. More often than not, you’ll be developing code on your desktop or laptop and deploying code to an embedded device.<\/p>\n\n\n\n
Getting everything set up to allow that to be seamless is often difficult to achieve.<\/p>\n\n\n\n
In this guide, I’ll show you how to configure your PC and a Raspberry Pi, to allow you to hit the F5 key in Visual Studio code and have the code shipped to the Raspberry Pi, run and have VS Code attach to the Visual Studio debugger actually on the Pi.<\/p>\n\n\n\n
There are alternatives to this methodology. One of them is the Remote SSH extension for VS Code<\/a>. However, this extension relies on the source code for your application to be stored on the device itself. I’m not a fan of this, as it means that you need to be consistently connected to the remote device to code. If you hop on a train and lose connectivity, you can’t save your work.<\/p>\n\n\n\n This guide (and single line install script!) will configure your system so you can code entirely on your local machine with no reliance on the remote machine until you need to deploy.<\/p>\n\n\n\n This guide is actually a simplified version of a previous post<\/a> I made about remote debugging .NET Applications on a Raspberry Pi from VS Code.<\/p>\n\n\n\n The previous version had relied on two different items; WSL with OpenSSH (primarily for rsync) and Putty’s Plink.<\/p>\n\n\n\n This version uses the free cwrsync <\/a>tool to remove the need for WSL entirely. Further, using Scott Hansleman’s instructions here<\/a>, we can remove the need for plink entirely.<\/p>\n\n\n\n Finally, I’ve created a one line script you can run from an elevated command prompt which makes getting your machine setup to Remote Deploy and Debug from Visual Studio Code a cinch!<\/p>\n\n\n\n Before you start, you’re going to need to have the following installed;<\/p>\n\n\n\n Instead of following along with a heap of instructions, I’ve created a script that carries out everything you need to prepare your pc to Remote Deploy and Debug .NET code from Visual Studio Code.<\/p>\n\n\n\n Open a command prompt as an Administrator and navigate to your root C drive with “cd \/<\/em><\/strong>“. <\/p>\n\n\n\n There are multiple versions of this script, depending on whether you are using .NET Core 3, .NET 5, .NET 6 or .NET 7;<\/p>\n\n\n\n The first thing the script will do is prompt you for the hostname of the Raspberry Pi you want to deploy your code to.<\/p>\n\n\n\n You’ll also be asked to enter the SSH password for the Pi, so the script can get the Pi setup to allow passwordless SSH – This is often simply “raspberry<\/em><\/strong>“.<\/p>\n\n\n\n This script will perform the following functions;<\/p>\n\n\n\nThe previous version of this guide<\/h2>\n\n\n\n
Prerequisites<\/h2>\n\n\n\n
The Quick Way – Run a script<\/h2>\n\n\n\n
For .NET Core 3 run…<\/h3>\n\n\n\n
curl --output remotedebugsetup.bat https:\/\/raw.githubusercontent.com\/pjgpetecodes\/dotnetcore3pi\/master\/remotedebugsetup.bat && remotedebugsetup.bat<\/code><\/pre><\/div>\n\n\n\n
For .NET 5 run…<\/h3>\n\n\n\n
curl --output remotedebugsetup.bat https:\/\/raw.githubusercontent.com\/pjgpetecodes\/dotnet5pi\/master\/remotedebugsetup.bat && remotedebugsetup.bat<\/code><\/pre><\/div>\n\n\n\n
For .NET 6 run…<\/h3>\n\n\n\n
curl --output remotedebugsetup.bat https:\/\/raw.githubusercontent.com\/pjgpetecodes\/dotnet6pi\/master\/remotedebugsetup.bat && remotedebugsetup.bat<\/code><\/pre><\/div>\n\n\n\n
For .NET 7 run…<\/h3>\n\n\n\n
curl --output remotedebugsetup.bat https:\/\/raw.githubusercontent.com\/pjgpetecodes\/dotnet7pi\/master\/remotedebugsetup.bat && remotedebugsetup.bat<\/code><\/pre><\/div>\n\n\n\n