Sorry for the hiatus, but I’m back now. I am crazy excited about .NET Core and I think it is going in an awesome direction. We use it at work and I wish I had more Raspberry Pi 2 & 3s laying around since they are capable of running it. The problem is that I still have ARMv6 Pi 1s and Zeros that need to be put to use! I worked this out a few years ago on my Pi 1, but the latest version of Mono that I could get on my Pi at that time was 4.0.2. That version can run older ASP.NET 5 projects, but not ASP.NET Core. I will show you how to get Mono 4.6.2, libuv 1.22.0, and ASP.NET Core 2.0 to all play nicely together on a Pi Zero.
First off, since I am using a Pi Zero, I needed either a USB Wifi dongle or an Ethernet adapter. I have used both but I prefer a wired connection since I plan to stream from this Pi in the future. This adapter worked perfectly right out of the gate. Then make sure you grab the latest version of Raspian Stretch to image your Pi’s SD card with. I used the Lite version since I am running headless. Remember that to communicate with the headless OS, enabling SSH is required. As directed,1 create a blank text file named “ssh” on the root of the Boot partition on the SD card. Further, if you are using WIFI, you need to create a text file named “wpa_supplicant.conf”. Copy the following text in that file and update at a minimum your ssid and psk:
Now that we can bash, let’s install Mono. This is where it used to be difficult. As I mentioned previously, when I first started playing around with ASP.NET, the default version of Mono on Rasbian was 3.2.8. I attempted to build Mono from source but ran into several problems, most likely because my ARMv6 Pis do not support hard floating point. At that time, I found two particularly helpful posts on how to point to a Jessie-specific Mono 4.0.2 repository which enabled me to run ASP.NET 5 applications.
http://www.hanselman.com/blog/HowToRunASPNET5Beta3OrGoLangOnARaspberryPi2.aspx https://www.thedju.net/articles/asp-net-core-mono-linux
Fast-forward and now Rasbian’s Mono version is 4.6.2, so we can just install it! Easy-peasy:
Now check out your Mono version. We’re all set!
At this point, it was important for me to ensure my old ASP.NET 5 application still worked. So I tried installing DNVM as outlined by dave dot ninja here. I hit a roadblock at the first command:
Running the dnvminstall.sh produces a 404 Not Found error. Sure enough, the URL for dnvm.sh in that script no longer exists. I knew DNVM is deprecated, but obsolete or not, this is the only way to run ASP.NET 5 on a Pi Zero. I found someone else looking for this, as well as confirmation that I would have to reference it in commit-specific links. Going back to Scott Hanselman’s post mentioned above, I modified his steps (his example was for the older KVM tool) to install the latest version of DNVM I could find (which happened to be tagged 1.0.1):
At this point, we know the dnvm.sh script copied to /home/pi/.dnx/dnvm/dnvm.sh by dnvminstall.sh is invalid, so I just overwrote it with the dnvm.sh from the repository and continued with the installation.
You should see your mono runtime listed:
As Scott further described, the “Kestrel” web server requires the libuv library. I modified his steps to build the current version of libuv. But trying to run “dnx run” yielded an error that Mono was unable to load DLL ‘libuv’. Argh. I looked back at some notes and remembered that Mono is looking for the library in /usr/local/lib. Added the symbolic links to that folder instead but still no dice. I went to my Pi 1 and verified that his steps worked for Mono 4.0.2 with /usr/local/lib and libuv 1.9.1. Back to dave dot ninja’s updated DNVM steps, I realized he had posted slightly different steps for building libuv. This worked perfectly (modified with updated version):
Now let’s see if we’re up:
If you see this then you are there!
Browse to your Pi’s IP address at the port listed above. After a minute or so you should see the sample ASP.NET 5 MVC website!
Awesome. Now you can create an ASP.NET Core project in Visual Studio and run it on your Pi 1 or Pi Zero. Here is a great tutorial on how to accomplish this:
https://www.c-sharpcorner.com/article/running-asp-net-core-2-0-via-mono/
I am planning a follow-up post to show how to create a simple ASP.NET Core website that streams video from the Raspberry Pi camera.