ASP.NET vNext on a Raspberry PI

ASP.NET vNext on a Raspberry PI

  1. Try number 1: raspbian with mono
  2. Try number 2: Windows 10 IoT Core on a Raspberry PI 2 with ASP.NET 5, Kestrel and DNX
  3. All done and time for the first test console application
  4. Lets create a Kestrel MVC application with DNX
  5. Publish the MVC application to my Raspberry PI 2
  6. Conclusion

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.
2015-12-19 15_30_45-InstantUpload - Bestanden - ownCloud

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
2015-12-19 15_25_14-Bestanden - ownCloud

The first thing to do is setting up all the variables and expanding the filesystem
2015-12-19 16_13_31-Photos 2015-12-19 16_15_53-Photos

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
2015-12-19 16_26_30-Photos

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
2015-12-19 16_42_40-Start

After installing the certificates I ran the following code
2015-12-19 16_47_28-Photos

At this point I found https://docs.asp.net/en/latest/getting-started/installing-on-linux.html#installing-on-debian-ubuntu-and-derivatives

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

2015-12-19 23_29_05-InstantUpload - Bestanden - ownCloud

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?
2015-12-19 17_28_29-Photos

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
2015-12-19 17_59_41-TL-WDR4300

The webpage could be found at http://10.0.0.113:8080
2015-12-19 23_35_50-Home
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
2015-12-19 18_01_31-Photos
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
2015-12-19 18_35_30-Photos

On my local machine I installed dnvm (.NET version manager) runtimes and architectures according to https://github.com/DamianEdwards/PiDnx
2015-12-19 18_38_35-Photos

All done and time for the first test console application

My environment at this moment:

Software Version
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
 Coffee Black

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

2015-12-19 23_46_46-New Project

It automatically download the missing packages when the project is created:
2015-12-19 23_47_28-New notification
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:
2015-12-19 23_50_02-

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
2015-12-19 23_53_09-Start
The command result:
2015-12-19 23_57_34-C__Windows_system32_cmd.exe
a lot of more lines…
2015-12-19 23_57_57-Search
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:
2015-12-20 00_00_42-approot

On the remote PowerShell connection I ran .\ConsoleApp1.cmd from the approot folder:
2015-12-20 00_02_44-Settings
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:

http://docs.asp.net/en/latest/fundamentals/servers.html#supported-features-by-server
2015-12-20 09_59_37-Servers — ASP.NET documentation
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
2015-12-20 09_36_07-Mail

To be able to select a APS.NET 5 Template I had to install AspNet5.ENU.RC1_Update1.exe

2015-12-20 09_37_21-Mail

After the project was created, the missing packages were also restored automatically
2015-12-20 09_38_09-New notification
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/
2015-12-20 09_40_54-Mail

In the run project selection (what is the name for this dropdown box?) select ‘web’
2015-12-20 09_46_38-Mail
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
2015-12-20 09_45_36-Mail

Opening a browser and navigate to http://localhost:5005 gave me my first webpage created with vNext
2015-12-20 09_43_49-

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)
2015-12-20 10_21_08-Mail

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
2015-12-19 23_53_09-Start

The output
2015-12-20 10_22_41-Mail
again a lot of lines more….
2015-12-20 10_23_26-Mail

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
2015-12-20 10_28_52-Mail

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)
2015-12-20 10_33_31-Mail

$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:
2015-12-20 10_35_07-Mail

Conclusion

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.

 

11 thoughts on “ASP.NET vNext on a Raspberry PI”

  1. I could install exact same version using following commands.

    set DNX_UNSTABLE_FEED=https://www.myget.org/F/aspnetvnext
    dnvm install 1.0.0-rc2-16319 -r coreclr -arch arm -u
    dnvm install 1.0.0-rc2-16319 -r coreclr -arch x86 -u
    dnvm install 1.0.0-rc2-16319 -r coreclr -arch x64 -u
    dnvm install 1.0.0-rc2-16319 -r clr -arch x86 -u
    dnvm install 1.0.0-rc2-16319 -r clr -arch x64 -u

    I will update if rest of the process worked…

  2. Any update on ASP.NET Core running on Raspberry Pi? Looks like ARM thread was left out. Or Am I wrong? Will latest ASP.NET Core 1.0 RTM will or on Raspberry Pi. Please enlighten. Thanks!

Comments are closed.