ASP.NET vNext on a Raspberry PI
- Try number 1: raspbian with mono
- Try number 2: Windows 10 IoT Core on a Raspberry PI 2 with ASP.NET 5, Kestrel and DNX
- All done and time for the first test console application
- Lets create a Kestrel MVC application with DNX
- Publish the MVC application to my Raspberry PI 2
Try number 1: raspbian with mono
I feel the need to have a lightweight ASP.NET server running at home. These days the vNext project is capable of running on Mono, making it possible to have my webpage running on a Raspberry PI.
In order to guide myself in this process, I have been following this guide www.talksharp.com/running-aspnet-vnext-on-the-raspberry-pi.
I have used one of my old Raspberry PI’s laying around, a new 8GB Class 10 micro SD card with adapter is used.
I have downloaded the lastest version of the raspbian image. These day’s the .img file is 3.66 GB, wow. I guess you get all the desktop functionality as well.
Using Win32 Disk Imager the .img file can be written to the SD card
The first thing to do is setting up all the variables and expanding the filesystem
After the easy install of mono I found out that I got the wrong version, version 3.2.8 is not the latest version and I need at least version 3.4.1 to get vNext running
After removing the package and following the installation instructions from blog.luppes.com/2015/03/19/mono-on-raspberry-pi I have now got version 4.2.1 installed
After installing the certificates I ran the following code
After that, I found some more Windows 10 IoT Core documentation and decided to switch from debian to Windows 10
Following the following guide http://ms-iot.github.io/content/en-US/win10/SetupRPI.htm
Try number 2: Windows 10 IoT Core on a Raspberry PI 2 with ASP.NET 5, Kestrel and DNX
What is DNX?
The .NET Execution Environment (DNX) is a software development kit (SDK) and runtime environment that has everything you need to build and run .NET applications for Windows, Mac and Linux. It provides a host process, CLR hosting logic and managed entry point discovery. DNX was built for running cross-platform ASP.NET Web applications, but it can run other types of .NET applications, too, such as cross-platform console apps.
The first step is to setup your Windows 10 IoT, the file comes in an ISO and contains only a .msi file, that could be easier to just download the .msi directly?
After booting the Raspberry PI 2, I went to my tp-link router and found the IP of the Raspberry PI 2 with Windows 10
The webpage could be found at http://10.0.0.113:8080
At this moment it felt like spending half a day and just finished only the first part of many…
After changing the default password and hostname I found that the Windows IoT Core Watcher, a small program that was installed before, found my device
Than I noticed this stupid application set itself to boot at startup of my development machine, really??
Next was to setup and test remote PowerShell http://ms-iot.github.io/content/en-US/win10/samples/PowerShell.htm to use it later in the deployment phase
All done and time for the first test console application
My environment at this moment:
|Windows 10 Pro 64-bit||10.0 (Build 10240)|
|Visual Studio Community 2015||14.0.24720.00 Update 1|
|Application Insights Tools for Visual Studio||4.0.51203.1|
I found an easy consoleApp1 tutorial at http://developers.de/blogs/damir_dobric/archive/2015/09/22/how-to-run-net-core-application-on-pi2-win10-iot-core.aspx
It automatically download the missing packages when the project is created:
So in the version I am using, there is no need to run the dnu restore command, that looks like an improvement if I compare it with the various tutorials.
After adding some test code it runs just fine on my local workstation:
To export my application, I ran the following commandline from the projects directory (wordpress removes some double – signs, see my printscreen for the good formatted command)
dnu publish –out “C:\Dev\aspnet_vnext\ConsoleApp1\output” –no-source –runtime dnx-coreclr-win-arm.1.0.0-rc2-16319
The runtime was copied from the ARM folder in %USERPROFILE%\.dnx\runtimes
The command result:
a lot of more lines…
I expected this to be easier, why is this not an option in the publish project menu from Visual Studio?
Next I copied all files in the output/approot directory to a folder on the Raspberry PI 2:
On the remote PowerShell connection I ran .\ConsoleApp1.cmd from the approot folder:
And there it was, my first application created with DNX running on my Raspberry PI 2.
Lets create a Kestrel MVC application with DNX
ASP.NET 5 is completely decoupled from the web server environment that hosts the application, it comes with support for 3 different servers:
The Kestrel project is standalone webserver based on libuv. Most notes on various websites claim that is still unstable, but my initial experiences were very good.
Creating a new MVC application
To be able to select a APS.NET 5 Template I had to install AspNet5.ENU.RC1_Update1.exe
After the project was created, the missing packages were also restored automatically
This looks more and more to be an incredibly easy job…
Next I found that it was required to set a parameter to the command.web part in the project.json file on https://blog.rendle.io/asp-net-5-dnx-beta8-connection-refused-in-docker/
In the run project selection (what is the name for this dropdown box?) select ‘web’
Yes, you can also run it with IIS Express, but as I will publish and run it on my Raspberry PI 2 later the web (Kestrel) option will give me the same environment on my localmachine as later on my Raspberry PI 2.
After building it on my development machine and running it the DNX console output tells you what is going on
Opening a browser and navigate to http://localhost:5005 gave me my first webpage created with vNext
Publish the MVC application to my Raspberry PI 2
Remove the prepublish line from the project.json (as it will fail on the bower part)
To publish the application, I simply repeat the steps to publish the commandline application:
I ran the following commandline from the projects directory
dnu publish –out “C:\Dev\aspnet_vnext\WebApplication1\output” –no-source –runtime dnx-coreclr-win-arm.1.0.0-rc2-16319
The runtime was copied from the ARM folder in %USERPROFILE%\.dnx\runtimes
again a lot of lines more….
Again I copied all files in the output directory to a folder on the Raspberry PI 2.
First, lets open port 5005 in the firewall on the Raspberry PI 2
netsh advfirewall firewall add rule name=”DNX Web Server port” dir=in action=allow protocol=TCP localport=5005
From the remote PowerShell connection I fired up the web.cmd command, but hell: errors
Luckily, it wasn’t just me getting this error https://github.com/aspnet/Home/issues/1111
The solution was to set the %PATH% so that my libuv was found (as it was published)
$env:Path += “;C:\aspnet_vnext\WebApplication1\approot\packages\Microsoft.AspNet.Server.Kestrel\1.0.0-rc1-final\runtimes\win10-arm\native”
Running the web.cmd again, it worked like a charm:
The idea of having a .NET application that can run on Windows or Linux, with a x86, x64 or ARM architecture, is just impressive.
While the versions I have used where still in development, only one bug (libuv path) interrupted my work.
As soon as the required publish process can be integrated in the Visual Studio publish wizard, development cycles can even be made shorter.
The documentation on the docs.asp.net webpage is far from complete, missing the update datetime tag on the pages make you wonder how old the information is, and against what version of the DNX project it was written.
I am very pleased with this environment, having the ability to host different versions of DNX on my Raspberry PI 2 will make the acceptation of a new environment much easier.
The development of ASP.NET 5 will be monitored closely by myself as from now.