'CMake problem: could not find any instance of Visual Studio

What I want to do

I got a source SDK file folder which contains all the files needed to create a project (or .sln), including a CMakeLists. And then I tried to use CMake to build a solution file. And this image below is the guide for how to get this SDK started.

SDK instruction guide

What I did

  1. Open Visual Studio 2019 (The CMake module have been installed).

  2. Open the SDK file folder with VS2019.

  3. Click "Tools" and open Visual Studio 2019 Developer Command Prompt v16.4.2.

  4. Type:

    mkdir build
    cd build
    cmake -G"Visual Studio 15 2017 Win64" ..
    

Problem

And I met the problem below:

CMake Error at CMakeLists.txt:2 (project):
  Generator 

Visual Studio 15 2017 Win64

  could not find any instance of Visual Studio.

-- Configuring incomplete, errors occurred!
See also "C:/Users/admin/Desktop/StructureSDK-CrossPlatform-0.7.3-ROS/build/CMakeFiles/CMakeOutput.log".


Solution 1:[1]

I ran into this problem when connecting to a windows build node from Jenkins via ssh.

What I was able to verify is that through the ssh connection running bash or windows cmd shell "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" would return no results.

However when running from local bash or cmd shell on the build node vswhere would return all the expected information.

After carefully comparing the differences in the two sets of environment variables ssh connection vs local setting ProgramData resulted in vswhere returning the expected results and CMake could find all installed Visual Studio instances.

In cmd shell set ProgramData=C:\ProgramData

In .bashrc export ProgramData='C:\ProgramData'

Solution 2:[2]

I had this same problem. I had version 16.9.3 installed of vs2019. I fixed the issue by running the vs installer. I clicked modify, the installer downloaded and installed 16.9.4, and after reboot cmake could properly detect that vs2019 was installed.

Note: When clicking modify, make sure "Visual C++ tools for CMake" is selected.

Solution 3:[3]

For me it work with visual studio 2022.

You should use an ide like visual studio code, android studio doesn't work and/or use this line : flutter config --enable-windows-desktop.

Have an nice day

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steven Fuhrman
Solution 2 einpoklum
Solution 3 Kai - Kazuya Ito