Want to get your ASP.NET Core apps working on Windows 10 IoT Core? Here's what you need to know using ASP.NET Core 2 and some minor hacking.
It has been problematic to run ASP.NET Core applications on Windows 10 IoT Core, as it is not an officially supported scenario yet, and many components we are used to are not built with Windows 10 ARM in mind. Still, it easy to run web applications on Windows 10 IoT Core using ASP.NET Core 2. There are few tricks developers should know when building web applications for Windows 10 IoT Core.
A few things to mention before getting our hands dirty with the real stuff:
- ASP.NET Core on Windows 10 IoT Core is not officially supported yet.
- There is only .NET Core runtime available for Windows 10 on ARM, but no SDK (yes, there is no dotnet restore and dotnet build, etc., available).
- Not all things that work on your dev box will work on Windows 10 IoT Core, and some of these things come out when trying to run a web application on a board.
With these warnings in mind, let’s start in safe waters and make a default ASP.NET Core 2 web application run on Windows 10 IoT Core.
Building the Web App
I created a default ASP.NET Core 2 web application with Visual Studio and made the compiler build an EXE file that can be run directly. Just open the project file and add this output type setting:
Now we can build a web application just to find out that the EXE file is not there. We will get it when publishing the application.
Before building and deploying our web application to our board, we have to make it listen port 5000 on all interfaces. For this, we modify the program class and use * as the host name.
To deploy our application to Windows 10 IoT Core, we need to publish it and tell the dotnet utility that we want to support Windows 10 on ARM. This is done using the following command.
If everything went well, then the published files are in the folder bin\Debug\netcoreapp2.0\win-arm\publish.
.
Deploying the Web App to Windows 10 IoT Core
To make a simple test run for our web application, we need to deploy it to Windows 10 IoT Core. Here are steps to follow.
- Open PowerShell with Administration permissions and run the following command:
Enter-PSSession -ComputerName minwinpc -Credential minwinpc\Administrator
When the login dialog opens, enter your Windows 10 IoT Core password. - Create a folder for the web application and move to this folder:
mkdir webapptest
cd webapptest - Open Windows Explorer and move to your board’s drive:
\\minwinpc\c$
Enter the password when asked, and then move to webapptest folder. - Take files from the web application publish folder and copy these to the webapptest folder created before.
- Run the following command in PowerShell to open port 5000 of board:
netsh advfirewall firewall add rule name=”ASP.NET Core Web Server port”
dir=in action=allow protocol=TCP localport=5000 - Next, in PowerShell, run the web application using the EXE file:
.\WebApplication6.exe
If there are no problematic dependencies in our web application, then we can see some output to the PowerShell window.
Notice that ASP.NET Core is listening to port 5000 on all network interfaces. Let’s open the application now using a browser.
We don’t see any debug output in PowerShell except exceptions (if there are any).
Note: The frst request to the web application is very slow, but after that, the app works fast and doesn’t put much load on the board. Most of the requests don't consume much CPU, and the working set of memory is around 104 MB.
Wrapping Up
Previously, it was harder to make ASP.NET Core applications run on Windows 10 IoT Core, but with ASP.NET Core 2, we can do it with less effort and hacking. All we had to do to make a default web application run on Windows 10 IoT Core was build it as an executable and then publish it to the board.
It is still risky business, as many things that run on usual boxes without any issues are not built with Windows on ARM in mind, and issues with these components usually appear when running the application on board. Still, we can use ASP.NET Core on Windows 10 IoT Core and come out with solutions where a simple web server on a board is needed.
Comments
Post a Comment