Skip to main content

Running ASP.NET Core 2 Apps on Windows 10 IoT Core

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:
<PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <OutputType>Exe</OutputType>
</PropertyGroup>

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.
public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }       public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseUrls("http://*:5000")
            .UseStartup<Startup>()
            .Build();
}

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.
dotnet publish -r win-arm

If everything went well, then the published files are in the folder bin\Debug\netcoreapp2.0\win-arm\publish.
.
ASP.NET Core 2 application published for Windows 10 IoT CoreThe size of the publish folder, in my case, is 73 MB.

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.
  1. 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.
  2. Create a folder for the web application and move to this folder: 
    mkdir webapptest
    cd webapptest
     
  3. Open Windows Explorer and move to your board’s drive: 
    \\minwinpc\c$ 

    Enter the password when asked, and then move to webapptest folder.
  4. Take files from the web application publish folder and copy these to the webapptest folder created before.
  5. 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
     
  6. 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.
ASP.NET Core 2 application running on Windows 10 IoT Core
Notice that ASP.NET Core is listening to port 5000 on all network interfaces. Let’s open the application now using a browser.
ASP.NET Core 2 application running on Windows 10 IoT Core
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

Popular posts from this blog

Python and Parquet Performance

In Pandas, PyArrow, fastparquet, AWS Data Wrangler, PySpark and Dask. This post outlines how to use all common Python libraries to read and write Parquet format while taking advantage of  columnar storage ,  columnar compression  and  data partitioning . Used together, these three optimizations can dramatically accelerate I/O for your Python applications compared to CSV, JSON, HDF or other row-based formats. Parquet makes applications possible that are simply impossible using a text format like JSON or CSV. Introduction I have recently gotten more familiar with how to work with  Parquet  datasets across the six major tools used to read and write from Parquet in the Python ecosystem:  Pandas ,  PyArrow ,  fastparquet ,  AWS Data Wrangler ,  PySpark  and  Dask . My work of late in algorithmic trading involves switching between these tools a lot and as I said I often mix up the APIs. I use Pandas and PyArrow for in-RAM comput...

Kubernetes Configuration Provider to load data from Secrets and Config Maps

Using Kubernetes Configuration Provider to load data from Secrets and Config Maps When running Apache Kafka on Kubernetes, you will sooner or later probably need to use Config Maps or Secrets. Either to store something in them, or load them into your Kafka configuration. That is true regardless of whether you use Strimzi to manage your Apache Kafka cluster or something else. Kubernetes has its own way of using Secrets and Config Maps from Pods. But they might not be always sufficient. That is why in Strimzi, we created Kubernetes Configuration Provider for Apache Kafka which we will introduce in this blog post. Usually, when you need to use data from a Config Map or Secret in your Pod, you will either mount it as volume or map it to an environment variable. Both methods are configured in the spec section or the Pod resource or in the spec.template.spec section when using higher level resources such as Deployments or StatefulSets. When mounted as a volume, the contents of the Secr...

Andriod Bug

A bug that steals cash by racking up charges from sending premium rate text messages has been found in Google Play.  Security researchers have identified 32 apps on Google Play that harbour the bug called BadNews. A security firm Lookout, which uncovered BadNews, said that the malicious program lays dormant on handsets for weeks to escape detection.  The malware targeted Android owners in Russia, Ukraine, Belarus and other countries in eastern Europe. 32 apps were available through four separate developer accounts on Google Play. Google has now suspended those accounts and it has pulled all the affected apps from Google Play, it added. Half of the 32 apps seeded with BadNews are Russian and the version of AlphaSMS it installed is tuned to use premium rate numbers in Russia, Ukraine, Belarus, Armenia and Kazakhstan.