Microsoft Visual Studio gets .NET Core debugging – on WSL2

'Higher fidelity local debugging experience' than debugging on Windows and deploying to Linux

4 Reg comments Got Tips?

Hands On Microsoft has pushed out an extension for Visual Studio 2019 that lets developers run and debug a .NET Core application on Windows Subsystem for Linux 2 (WSL 2).

The pre-release extension addresses what is now a common pattern for .NET Core developers: you use Windows to create and edit a web application or microservice, but deploy to Linux, gaining more deployment options and lower licensing costs. It may also perform better.

A test by developer Roberto Prevato in late 2017 found the same application performing significantly better on Linux.

More evidence that .NET Core runs well on Linux comes from Adtech company Criteo, which reports that "we migrated one of our biggest server consuming app out of windows. Running on .Net Core on Linux/Mesos/Marathon. 5300 mesos instances, 159k vCore, 320TB RAM evalutating 532M campaigns for 4M users every second. Less than 10ms on average."

Pic for .NET Linux piece

Click to enlarge

The new option gives what Microsoft calls a “higher fidelity local debugging experience,” compared to doing all your debugging on the Windows side before deploying to Linux and hoping it works the same.

The prerequisites are Windows 10 and WSL 2 with Ubuntu or Debian installed, and Visual Studio 2019, with the free Community edition good enough. The extension was previewed by Microsoft in its May virtual Build event, but is only now available to download.

We gave it a try. The extension seems well done. Once installed, a “WSL 2” option appears in the drop-down choices for starting a debug session, and when selected, prompts for installation of .NET Core 3.1 on the “remote” Linux operating system. It then automatically deploys the required files.

The .NET Core SDK gets installed on the Linux side, but the application source code remains in the Windows file system, accessed via the /mnt/[driveletter] path.

Our .NET Core web application worked first time, with little to show that it was running on WSL 2 other than messages in the Debug window about loading files from /mnt/c/Users/[username] and so on.

Breakpoints are hit, you can step through code, and everything works. We were not so lucky with a .NET Core React.js application, which complained about permission errors (node_modules/.bin/rimraf: node: Permission denied); but this is a pre-release.

How useful is it?

Microsoft offers various ways to debug .NET Core applications on Linux. One is to use Visual Studio Code running on Linux, which works pretty well and is arguably a better environment than Visual Studio for JavaScript debugging. Another is to run Visual Studio on Windows and deploy to a Linux Docker container; this has worked with debugging support for some time.

Another option is to use Visual Studio Code remoting, which lets you run the editor and debug on the Windows side while compiling and running on the Linux side. This is similar to how the new Visual Studio extension works, but takes more effort to set up. Unlike the new extension, though, VS Code remote development works with remote Linux servers as well as with WSL 2.

Since the idea is to verify that a .NET Core application runs the same on Linux as on Windows, it would be helpful if the Visual Studio test runner would execute tests in the WSL 2 environment - but this is not supported.

Some issues then, but another small piece in Microsoft's improving support for Linux development on Windows. ®

SUBSCRIBE TO OUR WEEKLY TECH NEWSLETTER


Biting the hand that feeds IT © 1998–2020