Scott Hanselman

Official Support for Remote Debugging a .NET Core Linux app in WSL2 from Visual Studio on Windows

July 24, 2020 Comment on this post [7] Posted in DotNetCore | Linux | VS2019
Sponsored By

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?

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.

WSL 2 in the Visual Studio Debugging Menu

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$ ls
DataProtection-Keys https
scott@IRONHEART:~/.aspnet$ cd https/
scott@IRONHEART:~/.aspnet/https$ ls
scott@IRONHEART:~/.aspnet/https$ ls -alogF
total 12
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!

About Scott

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.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
July 29, 2020 18:48
Question: The title says "remote debugging a .NET Core Linux app," but the screenshots and most of the article is talking about an ASP.NET web app. Why? ASP.NET Core apps can be debugged on Windows itself; they are sure to work the same on Linux.

Debugging a Linux console app, however, makes sense, because otherwise, one needs a full Linux installation.
July 31, 2020 1:11
Fleet Command - it's because a Web App, running in .NET Core under Linux is more complex (it exercises more) than a Console App. In fact, a Web App in .NET Core *is also a console app.* So yes, you can do all of these and both.

The reason you'd want to do this is to make sure that your deployment operating system for your app matches your development environment.
July 31, 2020 6:06
Great article Scott! Just used it to test my core app that I publish to a Linux app service. Had time zone issues that this helped me resolve.
August 07, 2020 13:50
That's really cool feature - so easy to use and really helps in code developement.
October 14, 2020 3:42
Read on for the full list of top 10 movies.
November 03, 2020 13:08
hello!,I like your writing so so much! share we keep in touch more approximately
your article on AOL? I need an expert on this space to unravel my problem.
Maybe that is you! Looking forward to look you.
November 05, 2020 19:03
Experts anticipate the COVIDSafe app is but to face its hardest
test, but six months on and the coronavirus "sunscreen" barely registers.

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.