Visual Studio CMake WSL project opens but no startup item (no executable detected)

1 week ago 10
ARTICLE AD BOX

I am trying to create a C++ CMake project targeting WSL in Microsoft Visual Studio.

What I did

Created a new project → CMake project

Selected location in WSL filesystem:
\\wsl.localhost\Ubuntu\home\g\project

Visual Studio created the files successfully, but did not open the project automatically

I manually opened it via:
File → Open → Folder → \\wsl$\Ubuntu\home\g\project

Project structure

Top-level CMakeLists.txt:

cmake_minimum_required(VERSION 3.10) project("wsl_c") add_subdirectory("wsl_c")

Inner wsl_c/CMakeLists.txt:

add_executable(wsl_c "wsl_c.cpp" "wsl_c.h") if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET wsl_c PROPERTY CXX_STANDARD 20) endif()

Problem

The project opens, but:

No targets appear in the startup dropdown

I get the message:
"Please select a valid startup item"

I cannot run or debug

Notes

The same setup works correctly if I create the project in C:\ instead of WSL

CMake configuration does not show obvious errors

WSL is installed and working

Question

Why does Visual Studio not detect the executable target in a WSL-based CMake project, and how can I fix it so that the target appears and can be run?

Is this a configuration issue, or a known limitation/bug with WSL + CMake in Visual Studio?

Read Entire Article