Use VS Code with WSL
Use the copy of VS Code installed in Windows; do not install a second copy inside WSL. Install this extension in the Windows copy of VS Code:
ms-vscode-remote.remote-wsl
Keep projects in the Windows filesystem
Use the same Windows project folder you created for local development. Do not put projects in OneDrive, Dropbox, or another synchronized folder, and do not create a second copy in the WSL home folder.
WSL mounts the Windows C: drive at /mnt/c. For example, the Windows project
C:\CSProjects\MyProject is available in WSL at:
/mnt/c/CSProjects/MyProject
Open the project in WSL
Open Ubuntu and change to the Windows project folder:
cd /mnt/c/CSProjects/MyProject
Replace the example path with the location of your project. Put quotation marks around the path if any folder name contains spaces. Then run:
code .
VS Code opens a new window connected to WSL. Look for WSL: Ubuntu in the lower-left corner. Terminals, builds, and debugging in this window now run inside Linux.
VS Code extensions that execute tools must also be installed in WSL. When prompted, install the recommended C/C++, Error Lens, Doxygen, Worklog, and Project Zip extensions in the WSL environment.
Switch between Windows and WSL
Close the current VS Code window before opening the project in the other environment.
Windows and Linux programs are not interchangeable, even when both are named
program.exe. Clean the old build before rebuilding:
- After moving from Windows to WSL, run
make clean, then build in WSL. - After moving from WSL to Windows, run
mingw32-make clean, then build in Windows.
Do not edit the project from Windows and WSL at the same time. Before moving between your computer and Codespaces, use the environment-switching checklist.