Visual Studio remote development with CMake - nothing happens when reopening the project

I’m using Visual Studio to connect to a docker container via SSH for remote development using CMake as the build system.
When Visual Studio launches the project for the first time or a CMakeLists.txt file has been altered, Visual Studio does some configuration, allowing me to view, compile and run the CMake targets, and other CMake settings also become available in the UI, however, when reopening the project, Visual Studio does not seem to detect the CMake Project or reconfigure automatically, meaning no targets are shown hence not possible to compile, or if shown don’t work, and no settings for CMake are shown in the UI; I could theoretically update a CMakeLists.txt file which after relaunching again could cause a regenerate, causing Visual Studio to detect the project, show the targets and general settings relating to CMake in the UI, but this is not ideal and could cause the entire project to require recompiling.

Steps to reproduce:

  1. Create C++ CMake Project in Visual Studio 2022
  2. Run Docker container and add SSH connection info in Visual Studio options
  3. Replace the default ‘x64-Debug’ in CMakeSettings.json with ‘Linux-GCC-Debug’
  4. Wait for automatic CMake generation or press Generate on the popup “C++ IntelliSense information may be out of date, generate the CMake cache to refresh…”
  5. Everything works perfectly now; the “Select Startup Item” menu button should be available to select, compile and execute the target/s specified from the CMakeLists.txt files. Other CMake buttons should now be available in the UI, (e.g. Project → Configure Cache)
  6. Quit Visual Studio
  7. Open the project again in Visual Studio
  8. There does not appear to be a way to restore the working state, Visual Studio does not know the CMake targets anymore, we can no longer compile the project, nor run it. There appears no way to cause Visual Studio to reconfigure within the UI. The existing targets may appear, but no longer work.

I have then followed the tutorial for remote cache: Open Existing CMake Caches in Visual Studio - C++ Team Blog

Doing the steps:

  1. Replace configuration ‘Linux-GCC-Debug’ with ‘Existing Cache (Remote)’
  2. Update cacheRoot to the path that contains CMakeList.txt on the remote system

The regenerate popup shows ( “C++ IntelliSense information may be out of date, generate the CMake cache to refresh…” ), pressing regenerate works the first time, but then subsequent re openings of the project result in nothing happening again. No targets / executables to choose.

This issue does not occur for local MSVC CMake projects, the available targets are always shown immediately upon relaunch, along with all other Project settings being available in the UI.

Could this be a bug in Visual Studio, or, is there something I’m missing so that Visual Studio always uses the existing cache to configure itself to make the targets available for compiling and executing, whenever I launch the existing project?
How do IDE’s discover the CMake targets?

I think it would be better to ask this in the Microsoft Visual Studio Developer Community. Microsoft are actually very responsive there. I don’t work with Docker but I have tried remote connections via SSH, and WSL, and both work as expected.