Ubuntu On Windows With Subsystem Linux

Dotnet and ASP NET Core are rapidly moving toward cross platform development. As of today, we are already able to write dotnet application running on Windows, Linux or docker. But when our development environment differs from our production environment, for example using Windows for development while deploying on Ubuntu, it can be hard to catch problems early. What we can do is spin off a virtual machine which we can use to test our application for development pruposes. Recently a new approach came to life thanks to Windows subsystems which allows us to run a Linux binaries executables natively on Windows 10. Today we will explore how we can run a Hello World ASP NET Core application locally on Ubuntu on Windows 10.

The first step is to get the public key for microsoft packages and place it into the trusted public keys by apt. This is meant to tell apt to trust the microsoft repository hence therefore inform apt that we trust the packages downloaded from the repository.

3. Run an ASP NET Core behind nginx

For a simple Hello World application, we create an empty template of ASP NET Core application called HelloWorld and run dotnet publish -c Release to publish it.

Next from the Ubuntu shell, we copy the binaries into /var/aspnetcore/hello-world/.

1

cp-r[path of publish folder] /var/aspnetcore/hello-world

And verify that we can run the application using dotnet HelloWorld.dll.

We can also make sure that we can hit the endpoint from the browser by going to http://localhost:5000.
Kestrel allows us to selfhost our application and if we hit the port, we can access the application. But it is not recommended to direclty hit Kestrel, instead it is best to pass by a reverse proxy like Nginx giving us more power in term of response, caching and of course act as a reverse proxy.

Install Nginx

Similarly as we installed dotnet, we can install nginx and start it.

1

sudo apt-get install nginx

Then we can start nginx.

1

sudo service nginx start

The configuration of nginx can be found in /etc/nginx/sites-available/default. Change the content of the file by the following:

That concludes today post on running a Hello World ASP NET Core application locally on Ubuntu on Windows 10.

Conclusion

Today we discovered how to install Ubuntu as a subsystem within Windows 10. Installing a Linux system gives us access to the powerful functionalities of bash. We then saw how to install dotnet on Ubuntu and how we could boot a Hello World application behind Nginx. Hope you liked this post. See you next time!