This tutorial demonstrates how to build and debug a simple Raspberry PI application using Visual Studio. The same steps will also work with Raspberry Pi 2.
- If you have not prepared your SD card yet, download WinFLASHTool and use it to write the image to the SD card:
- Start your Raspberry PI and connect a network cable to it.
- Please download and install the latest VisualGDB.
- On your Windows machine start Visual Studio, select “File->New project”. Then select “VisualGDB->Linux Project Wizard”. Specify project location and press “OK”.
- The VisualGDB Linux Project Wizard will start. As we are making a simple “Hello, World” application, keep “Create a new project” selected and press “Next”.
- If you have not created any Raspberry PI projects before, select “Create a new SSH connection” on the next page.
- Provide the IP address of your Raspbery PI box, the user name (“pi” by default) and password (“raspberry” by default). It is recommended to check the “setup public key” checkbox, so that VisualGDB will automatically generate an public/private keypair, store it in your Windows account’s key container and setup the Raspberry PI box to use it. If you don’t enable public key authentication, VisualGDB will remember your password for this connection. The stored passwords are encrypted using a key stored in your Windows account. Thus, the password will only be available once you login using your Windows account.
- You could use 2 options to build your first Raspberry PI app: build it on Windows with a cross-compiler or build it on the Raspberry PI itself. The first option is faster, while the second is easier to setup. In this tutorial we will use the second option: Use the diagram at the bottom of the page to check the correctness of your setup:
- The hammer icon corresponds to the machine
where the compiler is run. - The “play” icon corresponds to the machine where the debugged program is launched.
- The hammer icon corresponds to the machine
- When you press “Next”, VisualGDB will test your toolchain by trying to compile and run a trivial program. If any errors are detected at this stage, you will see a detailed error log with further troubleshooting information.
- As the same source code will be edited under Windows and then compiled under Linux, VisualGDB will need to keep the sources synchronized. The easiest way is to use automatic file uploading via SSH.
- Press Finish to complete the wizard. If this is your first project for Raspberry PI, VisualGDB will cache the include directories to make them available through IntelliSense.
- Replace the contents of the main source file with the following:246810#include <unistd.h>intmain(intargc,char*argv[])charszHost[128];printf('The host name is %sn',szHost);}
- Build the solution. You will see how the source files are transferred to Raspberry PI and compiled there:
- Set a breakpoint on the printf() line and press F5 to start debugging. The breakpoint will trigger:
- VisualGDB provides an advanced Clang-based IntelliSense engine that is fully compatible with GNU language extensions and provides advanced features like refactoring, Code Map and auto completion in the Watch windows:
- You can customize various project settings by right-clicking on the project in Solution Explorer and selecting VisualGDB Project Properties:
- You can now use all normal Visual Studio techniques to debug your app. If you want more examples, check out the following tutorials:
This video covers how to set up a windows machine with the required toolchain to begin programming the brand-new Raspberry Pi Pico. The toolchain has been in. In a previous video, I had posted instructions on installing Visual Studio Code on the Pi. That is nolonger necessary; you can now grab the ARM binaries stra. Visual Studio Code is officially distributed via the Raspberry Pi OS (previously called Raspbian) APT repository, in both 32-bit and 64-bit variants. You can install it by running: sudo apt update sudo apt. A Visual Studio Extension for debugging.NET Core applications remotely on a Raspberry Pi IMPORTANT:.NET 5.0 starting with the SDK 5.0.102 works now! You can use Visual Studio Code to develop and debug.NET Core applications either directly on your Raspberry or remotely from another computer but until today, there's been no easy way to use regular Visual Studio to develop and debug.
Developing for the Raspberry Pi Using Visual Studio To develop for the Raspberry Pi using Visual Studio, you must make sure that you installed the tools. You can check this by selecting “Custom installation” and checking the Universal Windows App Development Tools in the Features selection.
If you want to develop a kernel module for Raspberry PI an debug it over JTAG, follow this tutorial.
-->Deployment of .NET apps to Raspberry Pi is identical to that of any other platform. Your app can run as self-contained or framework-dependent deployment modes. There are advantages to each strategy. For more information, see .NET application publishing overview.
Visual Studio Code For Raspbian
Deploying a framework-dependent app
Visual Studio Raspberry Pi Gui
To deploy your app as a framework-dependent app, complete the following steps:
Ensure SSH is enabled on your Raspberry Pi. If needed, refer to Enable SSH in the Raspberry Pi documentation.
Install .NET on the Raspberry Pi using the dotnet-install scripts. Complete the following steps from a Bash prompt on the Raspberry Pi (local or SSH):
Run the following command to install .NET:
Note
This installs the latest version. If you need a specific version, add
--version <VERSION>
to the end, where<VERSION>
is the specific build version.To simplify path resolution, add a
DOTNET_ROOT
environment variable and add the .dotnet directory to$PATH
with the following commands:Verify the .NET installation with the following command:
Verify the displayed version matches the version you installed.
Publish the app on the development computer as follows, depending on development environment.
- If using Visual Studio, deploy the app to a local folder. Before publishing, select Edit in the publish profile summary and select the Settings tab. Ensure that Deployment mode is set to Framework-dependent and Target runtime is set to Portable.
- If using the .NET CLI, use the dotnet publish command. No additional arguments are required.
Using an SFTP client, copy the files from the publish location on the development computer to a new folder on the Raspberry Pi.
For example, to use the
scp
command to copy files from the development computer to your Raspberry Pi, open a command prompt and execute the following:Where:
- The
-r
option instructsscp
to copy files recursively. - /publish-location/ is the folder you published to in the previous step.
pi@raspberypi
is the user and host names in the format<username>@<hostname>
.- /home/pi/deployment-location/ is the new folder on the Raspberry Pi.
Tip
Recent versions of Windows have OpenSSH, which includes
scp
, pre-installed.- The
From a Bash prompt on the Raspberry Pi (local or SSH), run the app. To do this, set the deployment folder as the current directory and execute the following command (where HelloWorld.dll is the entry point of the app):
Visual Studio Raspberry Pi Simulator
Deploying a self-contained app
Visual Studio Raspberry Pi Development
To deploy your app as a self-contained app, complete the following steps:
Visual Studio Raspberry Pi C++
Ensure SSH is enabled on your Raspberry Pi. If needed, refer to Enable SSH in the Raspberry Pi documentation.
Publish the app on the development computer as follows, depending on development environment.
If using Visual Studio, deploy the app to a local folder. Before publishing, select Edit in the publish profile summary and select the Settings tab. Ensure that Deployment mode is set to Self-contained and Target runtime is set to linux-arm.
If using the .NET CLI, use the dotnet publish command with the
-r linux-arm
argument:
Using an SFTP client, copy the files from the publish location on the development computer to a new folder on the Raspberry Pi.
For example, to use the
scp
command to copy files from the development computer to your Raspberry Pi, open a command prompt and execute the following:Where:
- The
-r
option instructsscp
to copy files recursively. - /publish-location/ is the folder you published to in the previous step.
pi@raspberypi
is the user and host names in the format<username>@<hostname>
.- /home/pi/deployment-location/ is the new folder on the Raspberry Pi.
Tip
Recent versions of Windows have OpenSSH, which includes
scp
, pre-installed.- The
From a Bash prompt on the Raspberry Pi (local or SSH), run the app. To do this, set the current directory to the deployment location and complete the following steps:
Give the executable execute permission (where
HelloWorld
is the executable file name).Run the executable.