Create .NET Core Application And Deploy it to Raspberry Pi / ARM Device / Linux

Requirements:

  • Raspberry / ARM Device / Linux Device
  • SSH access to device / for deployment purposes
  • .NET SDK installed on Windows/Linux/Mac – where App will be developed
  • Windows Command Line SSH

Optional:

  • IDE / Visual Studio Code / Visual Studio

1. Create .NET Core application using command line / or Visual Studio

Command Line / Visual Studio Code

dotnet new console -o DotNet.RaspberryPi.App1

2. Build / Publish using Command Line

dotnet publish -c Release -r linux-arm

3. Deploy to Raspberry Pi device / Linux ARM Device

We will move / copy files to destination (ARM device) using SCP command, which stand for Secure Copy. Replace parameters to meet your needs.

  • Source Path / Folder
  • Destination Path / Folder
  • IP Address

scp -r <SOURCE-FOLDER> <USER>@<IP-ADDRESS>:<DESTINATION-FOLDER>

Example:

scp -r ./bin/Release/netcoreapp2.1/linux-arm root@192.168.1.150:/home/appUser/apps/

 

4. Run the App on the Device

First you’ll need to change permissions on executable ARM/Linux file by using chmod command. Also, move to publish directory where file is located.

This steps should be done on the device over SSH or direct connection. Connect to device using SSH command line command(alternative is Putty), Linux has command included by default.

IP address of the device can be found using:

  • nmap (nmap <IP-ADDRESS:RANGE-FROM>:<IP-ADDRESS:RANGE-TO>, example: nmap 192.168.1.1-255) or
  • you can go to your router and list devices. Router IP can be found using
    • ipconfig command line (Windows) or
    • ifconfig (Linux). Look for default gateway.

When you have all the parameters that you need, you can continue to executing the command below:

ssh <IP-ADDRESS>
#connecting to the remote device

cd /home/<USER>/apps/bin/Release/netcoreapp2.1/linux-arm/publish
#changing directory to publish folder

sudo chmod +x <AppName>
# change execution permissions on application

./<AppName>
#run application

Source Code

https://github.com/matejv1/DotNet.RaspberryPi.App1

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s