Running .NET Core on Raspberry Pi Raspbian

Easy guide to running .NET Core 2.0 applications on Raspberry Pi 2 and 3 with Raspbian.

What works

Tested on 16 July 2017. It is possible to run (but not build) .NET Core 2.0 applications on Raspberry Pi 2 and 3 with Raspbian. This is perfectly fine for me as I build on my Windows laptop and publish it for Linux ARM.

Steps

Install pre-requisites on RPi

Run the following to install runtime dependencies:

sudo apt-get update
sudo apt-get install libc6 libcurl3 libgcc1 libgssapi-krb5-2 libicu52 liblttng-ust0 libssl1.0.0 libstdc++6 libunwind8 libuuid1 zlib1g

Install pre-requisites on Windows

At time of writing, the version to use is .NET Core 2.0 SDK Preview 2.

Build and test Hello World ASP.NET Core

Create a new folder and name it whatever you like. Then change directory into it using command line:

dotnet new web

Take a look at the .csproj file. It should contain:

<TargetFramework>netcoreapp2.0</TargetFramework>

If the value is not netcoreapp2.0, something went wrong while installing .NET Core 2.0 SDK.

Next, restore dependencies using the following command:

dotnet restore

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.

Publish application for Linux ARM

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.0\linux-arm.

Copy the entire linux-arm folder contents to RPi. My preference is SFTP.

Run the application on RPi

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 &

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.

Support Me

If this post helped you, would you buy me a cup of tea/coffee?