CMake Error "could not find any instance of Visual Studio"

Had this issue at work. When of my colleagues (let’s call him Bob) messaged me with the following error:

cmake -S . -B build/ -G "Visual Studio 16 2019"
CMake Error at CMakeLists.txt:11 (project):
  Generator

 

    Visual Studio 16 2019

 

  could not find any instance of Visual Studio.
-- Configuring incomplete, errors occurred!

It took us a bit to figure out the solution though.

Bob had already installed VS2019 so we were confused why he was having an issue.

After looking online for a bit I discovered this is a bit of a common problem:

In general the key to solving this problem always seems to be reinstalling/modifying Visual Studio, which ends up repairing the environment so that cmake can find the Visual Studio instance.

What can be done to help users navigate this?
Is there a bug with Visual Studio installation?

EDIT: We are using cmake 3.19 to reproduce this issue. I don’t believe anything changed in 3.20 regarding this behavior.

CMake queries the VS Installer through a COM interface to ask for locations of VS instances. It asks only for completed installations, not partial installations, so if the VS Installer requires a reboot or something then it won’t report all installed VS versions.

One might be able to add a second query to ask the VS Installer for all instances, even those not fully installed. We shouldn’t use the latter, but if they are the only instance(s) available, we may be able to generate a better error message. E.g. “found incomplete installation X, check the VS Installer tool”.

1 Like

Should I make an issue on the GitLab then?

I opened CMake Issue 22082 for this.