DEV Community

Aditya Kanekar
Aditya Kanekar

Posted on • Updated on

Developing for Linux in Windows 10 with WSL 2 - Part 2

In the Part 1 we installed WSL 2 with Ubuntu 20.04 on our machine. To complete our development environment setup lets now install Dotnet Core on the newly installed VM. Launch Ubuntu 20.04 App from Start menu and follow along this article. We are going to install .Net Core 3.1.

wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-3.1
Enter fullscreen mode Exit fullscreen mode

Reference link for .Net Core installation,

  1. https://dotnet.microsoft.com/download/dotnet-core/3.1
  2. https://docs.microsoft.com/en-us/dotnet/core/install/linux
  3. https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu#2010-

Once installation is complete, run following command,

dotnet --version
Enter fullscreen mode Exit fullscreen mode

You should be able to see installed .Net Core version 3.1.xxx.

Launching VS Code from Ubuntu Shell

mkdir HelloWorld
cd HelloWorld

dotnet new console
Enter fullscreen mode Exit fullscreen mode

This will generate project for the console application. List the file in the directory by using ls command at the shell,

ls
Enter fullscreen mode Exit fullscreen mode

You should be able to see two files in the folder,

  1. HelloWorld.csproj -> Project file for console application
  2. Program.cs

To check if your application is running properly, run following command,

dotnet run
Enter fullscreen mode Exit fullscreen mode

This will print Hello World!

Congratulations, you have completed the first step. Now lets move to the interesting part, launching VS Code from Ubuntu app by entering following command,

code .
Enter fullscreen mode Exit fullscreen mode

You should be able to see that VS Code is downloading itself and in a few minutes you should see VS Code launched in Windows 10 with the project we just created. Wow that's what I called magic!

If you see a prompt to install C# extensions, click Install to complete the installation. Now click Program.cs from the Explorer menu,

Alt Text

You might get a prompt install tools for debugging and building .Net project, click Install. Now right click the Program.cs file from Explorer menu and click Reveal in Explorer. This will open your folder in Explorer. You will notice that the path is from the Ubuntu app, it will be something like,

\\wsl$\Ubuntu-20.04\home\xxxx\HelloWorld
Enter fullscreen mode Exit fullscreen mode

Running application in VS Code

To run your application Press F5, you will see Hello World! printed in the Debug Console window. The application is running in Windows 10 but on Ubuntu.

Debugging application in VS Code

To add a breakpoint, Press F9 inside the main method or alternatively you can click on the empty gutter on the left side. You should be able to see the familiar red-dot indicating the breakpoint is set. Now press F5 to launch the application, your application should pause at the breakpoint. You can press F10 to Step Over or F11 to Step Into the function.

So, there you have it you have successfully built a .Net Core application running on Ubuntu without leaving Windows 10.

Top comments (0)