Skip to content

How to install .NET Core on Raspberry Pi

.NET Core is a cross-platform version of .NET and its going everywhere. So here is my tale on how I got .NET Core running on Raspberry Pi 3B.

I have used RPI earlier running Windows 10 IoT and it was a very familiar experience as I have been more of a Windows guy for few decades. My non-Windows experience comes from working on Yocto Linux version for an embedded project and writing firmware on it.

Since the release of .NET Core, I wanted to experiment on non-Windows platforms, since .NET Core is a cross-platform version of .NET for building websites, services, and console apps. Other benefit is that we can run docker also on Raspberry Pi. So let us get started.

How to install Raspberry Pi?

Installing Raspberry Pi OS on an SD Card to boot the Raspberry Pi is pretty simple. You can go through the steps as mentioned here.

Lets check the Steps

  • Download .NET Core 3.1
  • Install .NET Core 3.1
  • Setting up path to make it work in all terminal session
  • Testing the install
  • First .NET Core Console App
  • SSH into RPI from Windows

Download .NET Core

You can either use the Raspberry PI desktop UI or command line wget

Use the gzip version, I am using RPI 3B here.

Download .NET Core 3.1 => sdk-3.1.301-linux-arm32-binaries
https://dotnet.microsoft.com/download/dotnet-core/3.1

Direct link to Linux ARM32 version is here in .gz format

Install .NET Core

Lets see the details for each command line

  • Create a folder called ‘dotnet’ inside the RPI HOME directory.
  • Next we extract the downloaded .gz file into the ‘dotnet’ folder we created.
  • Create an environment variable ‘DOTNET_ROOT’
  • Also add the folder to PATH variable
sudo mkdir -p $HOME/dotnet
sudo tar zxf dotnet-sdk-3.1.100-linux-arm.tar.gz -C $HOME/dotnet
export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$HOME/dotnet

Keep in mind, above steps work only for the current terminal session. In order to make it work in all terminal sessions we need few additional steps.

Enable ‘Show hidden’ files in the File Manager (CTRL-H) on RPI. You can find a file ‘/home/pi/.bashrc’ after that. Add the following 2 statements in this file at the end.

export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$HOME/dotnet

Time to test the install

If the output looks like below, its a confirmation that installation went through and now .NET Core is ready on your RPI.

pi@raspberrypi:~ $ dotnet --version
3.1.100

pi@raspberrypi:~ $ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.100
 Commit:    cd82f021f4

Runtime Environment:
 OS Name:     raspbian
 OS Version:  10
 OS Platform: Linux
 RID:         linux-arm
 Base Path:   /home/pi/dotnet/sdk/3.1.100/

Host (useful for support):
  Version: 3.1.0
  Commit:  65f04fb6db

.NET Core SDKs installed:
  3.1.100 [/home/pi/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.1.0 [/home/pi/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.0 [/home/pi/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

First .NET Core Hello World Console App on RPI

Create a folder for the project, switch to the new folder. Create a new ‘Hello World’ console app and run it. Command output should look similar to what is given below

pi@raspberrypi:~ $ mkdir helloworld

pi@raspberrypi:~ $ cd helloworld/

pi@raspberrypi:~/helloworld $ dotnet new console
The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on /home/pi/helloworld/helloworld.csproj...
  Restore completed in 854.14 ms for /home/pi/helloworld/helloworld.csproj.

Restore succeeded.

pi@raspberrypi:~/helloworld $ dotnet run
Hello World!

Let us check the program content

pi@raspberrypi:~/helloworld $ cat Program.cs
using System;

namespace helloworld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

Connecting to RPI from Windows using SSH

Use ifconfig from terminal console on RPI, to find the IP address of RPI. Since I am connected to WIFI IP is listed under wlan0. And the IP address is 192.168.1.31 in my case.

$ ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:b2:58:4c:de  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b8:27:eb:70:2c:f4  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.31  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::ba5c:5716:203c:9a89  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:25:79:a1  txqueuelen 1000  (Ethernet)
        RX packets 228870  bytes 308078058 (293.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 113567  bytes 11037680 (10.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I am running the ssh command from PowerShell console. But you can do the same from any command-line.

PS C:\> ssh pi@192.168.1.31
pi@192.168.1.31's password:
Linux raspberrypi 4.19.118-v7+ #1311 SMP Mon Apr 27 14:21:24 BST 2020 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Jul  7 14:39:19 2020 from 192.168.1.18
pi@raspberrypi:~ $

Hopefully this has helped you to setup the RPI with .NET Core easily. The steps should be very similar for running .NET Core on other Linux platforms.

1 Comment »

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

%d bloggers like this: