I had a similiar issue and noticed that I needed the following to be true:
Although I had installed WSL, I was missing an important individual component, make sure within the Visual Studio installer that you have installed the "C++ CMake tools for Linux" (in addition to the "Linux and embedded development with C++" workload)
Have WSL installed and set it up as a Remote Connection within visual studio. To do this follow the instructions on this page
wsl hostname -I