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.
- Microsoft: Try to break our first preview of 64-bit Visual Studio – go on, we dare you
- Microsoft flips request to port Visual Studio Tools for Office to .NET Core from 'Sure, we'll take a look' to 'No'
- Microsoft previews Hot Reload for .NET developers, sets date for .NET 6
- Microsoft emits more fixes for Exchange Server plus patches for remote-code exec holes in HTTP stack, Visual Studio
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. ®
- Asahi Linux
- Internet Explorer
- Linux Foundation
- Microsoft 365
- Microsoft Build
- Microsoft Edge
- Microsoft Office
- Microsoft Surface
- Microsoft Teams
- Office 365
- Patch Tuesday
- SQL Server
- Visual Studio Code
- Windows 10
- Windows 11
- Windows 7
- Windows 8
- Windows Server
- Windows Server 2003
- Windows Server 2008
- Windows Server 2012
- Windows Server 2013
- Windows Server 2016
- Windows XP
- Xbox 360