Build .NET Core apps on Windows, run it on Windows Subsystem for Linux.
If you do not know what Windows Subsystem for Linux (WSL) is, the short answer is that it allows you to run Bash on Ubuntu on Windows.
I will share my development environment setup where I do the following:
I needed to build apps on Windows then publish it to a Linux box to ensure that it works. Publishing it to a Linux VM on cloud is an option although ideally I would prefer the ability to run it locally. Running a Virtual Machine was my preferred option but it is slow to startup, uses more RAM, takes up a lot more disk space, etc. Then I decided to try WSL and it seems to work great.
Please refer to Bash on Windows installation guide. If you have WSL installed prior to Windows 10 Creators Update, the version of Ubuntu installed is 14.04. I do recommend that you uninstall and reinstall WSL to get Ubuntu 16.04. Then verify the version by running lsb_release -a
in Bash and you should be seeing:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial
Run the following commands (copied from .NET Core installation guide):
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893
sudo apt-get update
sudo apt-get install dotnet-dev-1.0.1
Download and install .NET Core SDK.
.NET Core SDK can generate basic Hello World examples so there is no need to Git clone an example to run. Just follow these simple steps on Windows Command Prompt or PowerShell:
DotnetCoreSample
on your Desktop.dotnet new web
dotnet restore
dotnet run
Browse http://localhost:5000
and you should be seeing Hello World
.
From WSL, you can access Windows files and folders.
For example, you can reach C drive
using (Note: The forward slashes):
cd /mnt/c/
If you are unfamiliar with Linux, here are few hints:
cd
just like Command Prompt except that you need to use forward slash (/).ls
whereas Command Prompt is dir
.To run an app on Linux (in this case Ubuntu 16.04 x64), we need to build/publish it for that specific environment:
dotnet publish --framework netcoreapp1.1 --runtime ubuntu.16.04-x64
Assuming your Username is JohnDoe, change Bash current directory using:
cd /mnt/c/Users/JohnDoe/Desktop/DotnetCoreSample/bin/Debug/netcoreapp1.1/ubuntu.16.04-x64/publish/
To run it:
./DotnetCoreSample
Browse http://localhost:5000
from your browser in Windows and you should be seeing Hello World
.