CMake: Visual Studio 15 2017 could not find any instance of Visual Studio

Solution 1:

I ran into the same error and performed the following steps to resolve the issue:

  1. Open Visual Studio
  2. Go to Tools -> Get Tools and Features
  3. In the "Workloads" tab enable "Desktop development with C++"
  4. Click Modify at the bottom right

These steps resulted in the "Visual C++ tools for CMake" feature being installed, but the other optional C++ features included in this workload may also helpful for what you are trying to do.

After the Visual Studio updater finishes installing try re-running the command. You may need to open a new command window.

Solution 2:

In my case, I installed Visual Studio, selecting the workloads and modules that I wanted, but I ignored the request to reboot, assuming that shutting down the computer at the end of the day and restarting it the following day would suffice. I was wrong.

The following day I tried a cmake build and got the "could not find any instance of Visual Studio" error. After several attempts to resolve, I re-ran the installer, made no changes to the configuration, and clicked Modify. This time I let it reboot the computer. The reboot took a long time. After which my cmake build worked.

Solution 3:

I had the same issue "could not find any instance of Visual Studio" but with Visual Studio 2019 (Community Edition) and I just had to configure the VS160COMNTOOLS variable so that CMake correctly detects Visual Studio.

export VS160COMNTOOLS="/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools"

(cf https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2016%202019.html)

With Visual Studio 15 2017, the variable you need should be VS150COMNTOOLS. (cf https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2015%202017.html)

NB: in my case, in a Travis-CI workflow, I installed Visual Studio using the commands (no need to reboot):

choco install visualstudio2019community
choco install visualstudio2019-workload-nativedesktop # required

With only the first package, CMake detection of VS2019 failed.