Official Support for Remote Debugging a .NET Core Linux app in WSL2 from Visual Studio on Windows
I've blogged before about Developing on Docker with the new and improved Visual Studio Container Tools (and WSL2) and also Remote Debugging a .NET Core Linux app in WSL2 from Visual Studio on Windows.
It's the second one that I'm talking about today. You can now run .NET Core console and web apps in WSL2 and debug them directly from Visual Studio 2019!
What do you need?
- .NET Core Tools: https://get.dot.net
- WSL 2: https://aka.ms/wsl
- Ubuntu or Debian distribution: https://aka.ms/wslstore
- Visual Studio 2019
Here's the experience in Visual Studio 2019 when the extension is installed. It "just works" and it makes it super easy to switch between running on Windows (under IIS or the Kestrel web server or under Kestrel under your default Linux distribution.
Check this out, you can see that .NET Core, from the Linux/WSL 2 perspective, is loaded out of /usr/share/dotnet/shared but my source remains on my /mnt/d drive (my Windows D:) and debugging Just Works.
You'll also notice that we are running on https://localhost:5001 and that localhost and ports from the Windows point of view maps to localhost and points (via a local tunnel that's transparent) to WSL 2.
How does the SSL cert work if WSL 2's Linux Kestrel web server is serving it?
You can see that there's a symbolic link between my WSL ~/.aspnet folder and my local profile in Windows so that this app shares SSL certs and that the same cert is served with Kestrel on Windows and Kestrel on Linux.
scott@IRONHEART:~$ cd .aspnet
scott@IRONHEART:~/.aspnet$ cd https/
scott@IRONHEART:~/.aspnet/https$ ls -alogF
drwxr-xr-x 2 4096 Jun 23 17:02 ./
drwxr-xr-x 4 4096 Jun 23 17:02 ../
lrwxrwxrwx 1 71 Jun 23 17:02 hanselminutes.core.pfx
I broke that line up with the symbolic link -> along 3 lines so it wouldn't wrap on this blog.
Now you can run and debug .NET Core apps on Windows and Linux using both VS Code and Visual Studio 2019! I'm using Visual Studio 2019's free Community Edition and it works great. This helps me save money as I've moved my Podcast site to Linux in Azure and it makes my local development better match my cloud reality. Give it a try!
Sponsor: Centralize and search structured application logs to confidently diagnose problems - even faster and easier with Seq 2020.1!
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
The reason you'd want to do this is to make sure that your deployment operating system for your app matches your development environment.
your article on AOL? I need an expert on this space to unravel my problem.
Maybe that is you! Looking forward to look you.
test, but six months on and the coronavirus "sunscreen" barely registers.
Comments are closed.
Debugging a Linux console app, however, makes sense, because otherwise, one needs a full Linux installation.