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

Hugo 6 Reputation points
2022-01-24T21:24:20.37+00:00

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

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?
Whilst not ideal, is there a way to manually run CMake reconfigure in Visual Studio?

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"]
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,525 questions
{count} votes