Exploring Raspberry Pi 4 with C#

01 Mar 2020

This guide will help you in installing .Net Core and use C# on your Raspberry Pi 4.

Prerequisites

  • Raspberry Pi 4 with ready-to-go Raspbian system installed

Note

I cover two different approaches on how to install .Net Core on Raspberry device. The first one is easier as we need to have a browser while the other one assumes that we do not have any browser (or do not want to) and that is why a behavior is slightly different.

Before installing .Net Core 3.1

Before the installation, we need to check if we already have installed all dependencies needed by .Net Core.

Visit this page and check which packages do you need. Raspbian is based on Debian, so we need to install:

  • libicu63
  • libssl1.1

Open a terminal application on your Raspberry and run the following commands (note that we also need to install wget in order to download .net core package itself):

1sudo apt-get -y update 2sudo apt-get -y install wget libicu63 libssl1.1

Download and install .Net Core

Unfortunately, at the moment this is no a simple way to install .Net Core using apt-get command. We need to download a distribution tar archive and install it manually. So here we go.

  1. Go to .Net Core download page and find the latest stable version. In my case, it is .Net Core 3.1.
  2. Open that page in the browser and find ARM32 binary file under SDK section. After clicking the link, a new page will open and download will immediately start.
  3. Open a terminal and execute a command sudo mkdir -p /usr/share/dotnet This will create a necessary directory.
  4. Switch to your Downloads folder and execute another script to unpack downloaded archive: sudo tar -zxf dotnet-sdk-3.1.102-linux-arm.tar.gz -C /usr/share/dotnet
  5. Then you need to create a symbolic link to the dotnet command. This will make dotnet command accessible through the terminal session. sudo ln -s /usr/share/dotnet/dotnet /usr/bin
  6. That is all! Let’s check that everything works by executing a command dotnet --version And you should see something like this 3.1.102

What if you want to use wget instead of a browser?

Follow these additional steps if you don’t have a browser installed or do not have a desktop environment at all at your Raspberry (it calls headless).

  1. You need to install wget in order to download .Net Core distribution package. To do this run (being on the part of a prerequisite of the article) the following command in the terminal: sudo apt-get -y install wget

  2. While we used the distribution file downloaded from a browser, in this case, we need to do this via wget we just downloaded. After clicking the link, a new page will open and download will immediately start. But this behavior is useless for us, as we want to do the installation by a command line.

    Fortunately, there is a link click here to download manually so we can copy the full link address and use it for our purpose. Copy this link address. In my case the URL is https://download.visualstudio.microsoft.com/download/pr/349f13f0-400e-476c-ba10-fe284b35b932/44a5863469051c5cf103129f1423ddb8/dotnet-sdk-3.1.102-linux-arm.tar.gz

  3. Run this command for download (use your URL) wget https://download.visualstudio.microsoft.com/download/pr/349f13f0-400e-476c-ba10-fe284b35b932/44a5863469051c5cf103129f1423ddb8/dotnet-sdk-3.1.102-linux-arm.tar.gz

  4. Next, follow from 3rd step of the main tutorial but keep in mind that by default wget command saves downloaded files in /pi directory.

That is all

Now you are ready to develop amazing applications in C# for Raspberry Pi.