Skip to content

Woselko/Build-Debug-.NET-RaspBerryPi5

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image image image

How to build, publish and deploy .NET application on Raspberry Pi 5

Prerequisites:

  • VS Code installed on your PC or laptop
  • Operating system is installed on your Raspberry (https://www.raspberrypi.com/software/) You can also use RPI-imager to install system by command “sudo apt install rpi-imager”
  • Your PC or laptop and your Raspberry Pi are connected to same WI-FI network
  1. You need to know your Raspberry IP address. If it is connected you can find it while hovering WIFI icon in top right corner. You can also use command “hostname -I” in Raspberry terminal.

image

  1. Enable SSH server in raspberry Run command “sudo raspi-config” select “Interface Options” and enable access using SSH

  2. Enable SSH server in Windows Open “Settings” > “Apps” > “Apps & Features” > “Optional Features. Select “Add Features” and “OpenSSH Server” and “Install” (admin rights required). Set the startup type for “OpenSSH Authentication Agent” and “OpenSSH Server” to “Automatic” in the Windows “Services” app.

  3. Now you should be able to connect via windows CMD to your raspberry Use command in windows cmd “ssh userName@IP”. You’ll be asked for password.

  4. Generate an ssh key pair (private-public) on your local computer First, check if you already have one. Default all the ssh keys are located in ~/.ssh folder on your computer. If you don’t have this folder or it’s empty you don’t have. To generate a new rsa key pair go to Terminal and simply type and follow the steps ssh-keygen ~/.ssh/id_rsa — This is your private key. NEVER share this file with anybody and DO NOT copy this file to external computers/servers. ~/.ssh/id_rsa.pub — This is the public key. The content of this file can be shared and the content of this file we will need to copy to the raspberry pi.

  5. Run command "ssh-keygen" on Raspberry Pi, leave empty, press ENTER Now look inside your .ssh directory: “ls ~/.ssh” and you should see the files id_rsa and id_rsa.pub: authorized_keys id_rsa id_rsa.pub known_hosts

  6. Copy public key to Raspberry Pi vim ~/.ssh/authorized_keys // paste in this the content of the ~/.ssh/id_rsa.pub from your local computer

Or open file manually and paste content from your local PC .pub file

run command “ssh-copy-id USERNAME@IP-ADDRESS”

You'll be asked for a password

Now try to connect once again from your local PC via SSH, connection should be passwordless

Install DOTNET on Raspberry device (https://learn.microsoft.com/en-us/dotnet/iot/deployment)

  1. Run command curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel STS

  2. Add .NET as a path by commands:

echo 'export DOTNET_ROOT=$HOME/.dotnet' >> ~/.bashrc

echo 'export PATH=$PATH:$HOME/.dotnet' >> ~/.bashrc

source ~/.bashrc

  1. Verify .NET installation by command “dotnet --version”

Create .Net Application

Run command “mkdir NetRasp“ that will create folder in your RaspBerry folder: /home/woselko/NetRasp Run command “dotnet new console -n NetRaspApp” that will create a console app

  1. Run command “curl -sSL https://aka.ms/getvsdbgsh | /bin/sh /dev/stdin -v latest -l ~/vsdbg”

Open your app in VS Code editor

Install below extensions to help ssh connection via vs code image

Type in vs code Ctrl+Shift+P to open Command Pallete and run below command image

+Add New Connection Host and type your Raspberry creds @ image

And Connect Select Open Folder

image

Open your main app folder

image

After Successful opening you’ll be asked for adding .net vs code assets, it will be very helpful during build, publish and deploy app.

image

Check .vscode/tasks.json to see how build, publish, deploy task is performed, you can you use those patters Check .vscode/launch.json to see how launch and debugger is attached REMEMBER to change your credentials and check paths After all you should be able to run your app and breakpoints should be hitted.

image

After successful RUN, application should be build, published and deployed to below location

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages