Ozzie.eu

Ozzie.eu

Love to code although it bugs me.

11 Jun 2021

Using Windows Subsystem for Linux for cross-platform testing

Windows Subsystem for Linux is a wonderful feature to perform cross-plataform testing without having to install 3rd party virtualization software or containers.

It’s been around as an optional feature on Microsoft’s Windows 10, since 2016. With the release of WSL2, users can now use a genuine linux kernel running on top of a Virtual Machine Platform based on a subset of Hyper-V features.

Before you proceed, be sure you’re running all the latest Windows updates. Then, you can follow the steps on the official documentation.

After installing the features, go to the Microsoft Store on your Windows machine and download your linux distro of choice, from the available ones. My personal favourite is Ubuntu.

With the goal of developing and testing .NET core applications in linux, you should open a CLI to the linux distro you just downloaded and complete the setup steps. Afterwards, execute the following commands to install .NET 5:

wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb 
sudo dpkg -i packages-microsoft-prod.deb
sudo apt update 
sudo apt install apt-transport-https
sudo apt install dotnet-sdk-5.0

Having done so, hopefully with success, test you installation:

dotnet --version

At the time of this writing, it reported version 5.0.301 installed.

Having the .NET 5 SDK installed, I downloaded a copy of my side project automate-dotnetcore onto the WSL filesystem and performed the “dotnet build” and “dotnet run” seamlessly with no errors.

In conclusion, I’m now able to develop .NET 5 applications and test their cross-platform compatibility without the added burden of maintaing or even buying 3rd party virtualization software.