Install .NET core on Raspberry Pi with Raspbian

core

This article will be the first of a serie about .NET Core and raspberry pi.
The first one will be about how to install .NET Core on the raspberry and test its validity.

Install raspberry part

First of all you will need to install some packages running the following command line:

sudo apt-get install libunwind8 libunwind8-dev gettext libicu-dev liblttn g-ust-dev libcurl4-openssl-dev libssl-dev uuid-dev

In order to download and install the latest version available of .NET Core, youw should visit this page, you will find here the version you need.
Then when you have the url of the version you want, you can go to your raspberry in order to download and install it.
Then run the following command (exemple):

sudo wget https://dotnetcli.blob.core.windows.net/dotnet/Runtime/master/dotnet-runtime-latest-linux-arm.tar.gz

This will download the file and put it on the folder where you are currently. Once you have download the archive, you will need to « unzip » it with the following command:

sudo tar -xvf dotnet-runtime-latest-linux-arm.tar.gz -C /home/raspbian/dotnet

As you can see, the content of the archive will be extract to the folder "/home/raspbian/dotnet"

To check if the installation succeed run in the folder where you unzip the archive the following command line :
dotnet --info
You should see something like this:

One thing I usually do is to create a shorcut for the command, in this way, I will be able to run dotnet in every folder.
To do so, you have to run this:

sudo echo "PATH=\$PATH:home/raspbian/dotnet" >> dotnetcore.sh

This will create a sh file
Then move the file to profile.d

sudo mv dotnetcore.sh /etc/profile.d

Then reboot your device, the installation should be complete now!

Intall windows part

For windows it’s much more simple, I will just need to install the SDK, to find it just go to this page download the MSI and then run it.

Open Powershell and run dotnet --version
You should see something like that:

I also recommend you to install VS Code, which will be usefull to work with .NET Core.

Create a hello world

What’s left now is to create a simple hello world console application and run it on the raspberry!

On your Windows computer, using Powershell run the following command:

dotnet new console

This will create a really simple project:
coreproject

In this project you will find a csproj file, if you open it, its quite simple:

Exe
netcoreapp2.0
It just define the target framework of your project.
However in my case there is a difference of version between the SDK on my Windows and the runtime on my Raspberry. In order to align both, I will make a small modification to the csproj:

Exe
netcoreapp2.0
2.1.0-preview1-25326-01

We are almost done, just tow more command line with Powershell
dotnet restore
dotnet build

Now you have an application build and ready to run.

Just copy the content of the « bin/debug » to your raspberry using Winscp for exemple, once you copy it, go back to your Pi and go to the folder you just copy and run:

dotnet myApplication.dll
helloworld

That’s all, you are now able to install .NET Core and run a simple application on raspberry pi.

Un commentaire

Répondre

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion /  Changer )

Photo Google

Vous commentez à l'aide de votre compte Google. Déconnexion /  Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s