Search code examples
visual-studiocmakeremote-debugging

Visual Studio remote development 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 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:

  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, (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: https://devblogs.microsoft.com/cppblog/open-existing-cmake-caches-in-visual-studio/

Doing the steps:

  1. Replace configuration 'Linux-GCC-Debug' with 'Existing Cache (Remote)'
  2. Update cacheRoot to the path that contains CMakeCache.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.

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"]

Solution

  • 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.