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 configures, allowing me to view, compile and run the CMake targets, and other CMake settings also become available in the UI (such as settings from the 'Project' drop down), 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:
I have then followed the tutorial for remote cache: https://devblogs.microsoft.com/cppblog/open-existing-cmake-caches-in-visual-studio/
Doing the steps:
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.
Is this 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 typically detect CMake targets, perhaps knowing this could give a hint on solving the issue.
Visual Studio Version: 17.0.5
Docker File:
FROM ubuntu:21.04
ENV DEBIAN_FRONTEND="noninteractive"
RUN apt update && apt install build-essential gdb rsync zip openssh-server sudo cmake ninja-build -y
RUN echo "root:dev" | chpasswd
RUN echo "AllowUsers root" >> /etc/ssh/sshd_config
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN service ssh start
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]
This is a known bug in Visual Studio 2022 - https://developercommunity2.visualstudio.com/t/VS-2022-cant-reopen-cmake-project-on-re/1591862?entry=problem
Try updating to the latest version or downgrade to Visual Studio 2019.