Unlike WSL1 that shares the same IP addresses (including localhost) between Windows and Linux sides, WSL2 distros run inside separate lightweight virtual machines and cannot directly communicate to the Windows host unless explicitly enabled in firewall settings.
VisualGDB relies on the ability to communicate between the WSL target and Windows, hence in order to use WSL2 targets with VisualGDB, you would need to enable TCP/IP connections from WSL2 hosts. The easiest way to configure it is shown below:
- Locate PowerShell in the Start menu, right-click on it and select “Run as Administrator”.
- In the Administrative PowerShell Prompt run the following command:
1New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
- Now you can select WSL2 targets in VisualGDB dialogs and they will work out-of-the-box, just like WSL1 targets.