This article is more than 1 year old

Visual Studio 2022 Preview 2 adds C++ build and debugging in WSL2 distributions

Fancy a spot of weekend tinkering?

Amid the puffery over Windows 365, Microsoft also released the second preview of Visual Studio 2022 with some intriguing features for Windows Subsystem for Linux 2 users.

Visual Studio 2022, now finally available in 64-bit flavour, also added a range of additional languages in the update and new Live Preview experiences for XAML and web apps. However, for developers toiling away at the coalface of C++, the availability of a native Windows Subsystem for Linux 2 (WSL2) toolset should make life a little simpler.

WSL2 is Microsoft's latest and greatest attempt at bringing Linux apps to Windows. Where its predecessor was a translation layer, the new shiny runs in a lightweight virtual machine and sports a full Linux kernel for much improved system call compatibility.

WSL1, however, still had the edge with the native WSL1 toolset introduced in Visual Studio 2019 16.1, which permitted the building and debugging of C++ code on WSL1 distros.

Preview 2 (and goodness, this is very much a preview and not really ready for production workloads as yet) adds the WSL2 toolset, allowing the C++ code debugging on WSL2 distros without having to faff around with the likes of SSH connections.

While the toolset supports both CMake and MSBuild-based Linux projects, Microsoft recommends going for CMake for cross-platform development "because it allows you to build and debug the same project on Windows, WSL, and remote systems."

We took the new toys out for a spin, adding the extra danger of a preview build of Windows 10 to the not-for-production emission of Visual Studio 2022 and came away impressed by the potential, even if we stumbled a bit with the implementation (but will cut the code some slack, it being relatively early days in development). Admittedly, our crude "Hello world!" hardly taxed things, but was neat nonetheless.

As for how it works, Visual Studio executes a local rsync to shunt files from the Windows file system to WSL. Hitting Start in Visual Studio 2022 launches the executable on the WSL2 distribution and the output is squirted out into the Linux Console window of VS. Breakpoints and the like work as expected for debugging.

There are dependencies. A C++ compiler is required in the distro as well as tools including rsync, zip, and, of course, CMake. CMake Presets integration must also be enabled in Visual Studio.

However, once done (and the WSL2 target distribution selected), the process is painless and stable. At least it was in the case of our simple app. We'd recommend some experimentation with the technology if C++, Visual Studio and cross-platform development is your thing.

While this remains in preview, it is yet another demonstration of Microsoft's determination to embrace a cross-platform world. ®

More about


Send us news

Other stories you might like