Easy guide to building and running .NET Core 2.1 applications on Raspberry Pi 2 and 3 with Raspbian Stretch.
It is possible to run and build .NET Core 2.1 applications on Raspberry Pi 2 and 3 with Raspbian. Previously, the SDK could not be installed onto Pi.
In my setup, I am using Raspbian Stretch Lite because I do not need desktop environment. This guide should work for the full variant nonetheless.
As at 8 July 2018, Microsoft does not list Raspbian as a supported distribution on its documentation.
However, there is a post on StackOverflow indicating that .NET Core 2.1 is supported on Raspberry Pi.
Below will install .NET Core SDK 2.1.300:
sudo apt-get -y update
sudo apt-get -y install libunwind8 gettext
wget https://dotnetcli.blob.core.windows.net/dotnet/Sdk/2.1.300/dotnet-sdk-2.1.300-linux-arm.tar.gz
wget https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/2.1.0/aspnetcore-runtime-2.1.0-linux-arm.tar.gz
sudo mkdir /opt/dotnet
sudo tar -xvf dotnet-sdk-2.1.300-linux-arm.tar.gz -C /opt/dotnet/
sudo tar -xvf aspnetcore-runtime-2.1.0-linux-arm.tar.gz -C /opt/dotnet/
sudo ln -s /opt/dotnet/dotnet /usr/local/bin
dotnet --info
Create a new folder and name it whatever you like. Then change directory into it using command line:
dotnet new web
This should also perform dotnet restore
implicitly.
Take a look at the .csproj
file. It should contain:
<TargetFramework>netcoreapp2.1</TargetFramework>
Verify that the application works by running:
dotnet run
You should be seeing:
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
To be able to run this application on RPi, it is necessary to publish the application for that specific environment.
dotnet publish -r linux-arm
The published output appears under bin\Debug\netcoreapp2.1\linux-arm
.
Copy the entire linux-arm
folder contents to RPi. My preference is SFTP.
From here on, perform the steps below on Raspberry Pi.
Grant the HelloWorld binary execute permissions or else you cannot run it:
chmod 755 HelloWorld
Then run the application in the background without outputting to console:
./HelloWorld > /dev/null &
Do NOT run the exe/dll file. Run the extensionless binary.
You should be seeing output like below where the xxxxx is the Process ID (PID):
[1] xxxxx
Give it a few seconds to startup.
Perform a simple HTTP test using:
curl http://localhost:5000
If you see Hello World!, congratulations. You have successfully completed this super simple tutorial.
I prefer using containerisation over manually installing pre-requisites into the system to keep the system clean. Docker images can be found on Docker Hub. I have verified that the console and web application samples do work on Raspbian Stretch.