With the raise of microservices, it is more and more common to develop .NET applications on Windows and deploy them on Linux. There are lots of differences between Windows and Linux, so you should better debug on Linux directly instead of Windows to avoid errors on production. In Visual Studio, you can use Docker to debug your application on Linux. If you don’t use Docker to deploy your application, setting up a Docker file take times and knowledge. You could also use SSH to debug an application running on Linux, but the development workflow is not convenient.
The new Visual Studio extension allows to quickly run and debug a .NET application on WSL 2 from Visual Studio. WSL 2 includes a Linux kernel, so this is very similar to executing the app on an actual Linux machine. Also, WSL 2 is convenient as it shares the same file system as Windows, so you can easily switch between debugging on Windows and debugging on WSL.
Note: WSL 2 was initialy only available in Windows 10 version 2004, but it is being backported to Windows 10 version 1903 and 1909 (announcement)
wsl --list
wsl --setdefault Ubuntu-20.04
Install the VS Extension: .NET Core Debugging with WSL 2 - Preview
Change the Debug target:
Install .NET and vsdbg in the WSL instance if needed using the button in the Visual Studio gold bar and the error window:
#.net #tools