Running .NET Core on Raspberry Pi Raspbian

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

Updates

  • 2018-03-10: Updated this guide to be compatible with Raspbian Stretch

What works

It is possible to run (but not build) .NET Core 2.0 applications on Raspberry Pi 2 and 3 with Raspbian. This means the SDK cannot be installed onto Pi. This is perfectly fine for me as I build on my Ubuntu laptop and publish it for Linux ARM.

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.

Steps

Install pre-requisites on RPi

As at 10 March 2018, Microsoft does not list Raspbian as a supported distribution on its documentation. However, the dependencies listed for Ubuntu 17.x is almost the same.

sudo apt-get update
sudo apt-get install libunwind8 liblttng-ust0 libcurl3 libssl1.0.2 libuuid1 libkrb5-3 zlib1g libicu57

The only thing that is different is swapping out libssl1.0.0 for libssl1.0.2.

Install pre-requisites on Windows/Mac/Linux

The version to use is .NET Core 2.0 SDK.

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

This should also perform dotnet restore implicitly.

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.

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 &

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.