cmake problems with MSBuild.exe

have problems with cmake on Windows 10. I pruned things to the smallest example that will generate the same errors. I run cmake from the Windows command prompt (the same problem occurs with the git bash command-line interpreter, of the Visual Studio command prompt ). My CMakeLists.txt contains three lines:

    cmake_minimum_required(VERSION 3.1)

    project(DEBUG bogus)

I run cmake this way:

cmake -G "Visual Studio 15 2017 Win64" .

A MSBuild.exe window pops up briefly with an error message, but I can’t read it. It’s gone too fast.

The command-line window displays this error message:

CMake Error at CMakeLists.txt:3 (project):

  Failed to run MSBuild command:

    C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/MSBuild/15.0/Bin/MSBuild.exe

  to get the value of VCTargetsPath:

-- Configuring incomplete, errors occurred!

See also "C:/Users/tmpuser/Desktop/SDK/dependencies/DEBUG/CMakeFiles/CMakeOutput.log".

The executable for MSBuild.exe does indeed exist. The CmakeOutput.log file contains:

The system is: Windows - 10.0.17763 - AMD64

Does anyone know what is wrong?

Could you try running this instead? I’m not sure why you are calling the project command like that.

cmake_minimum_required(VERSION 3.1)


Thank you. Yes, I tried that and it produced the same result.

The error wasn’t necessarily that MSBuild.exe couldn’t be found but that getting the value of VCTargetsPath failed.

There are a few open / closed issues that can be found when searching for VCTargetsPath

I would first check that MSBuild.exe is working and building projects from the command line to verify the installation is working correctly.

Thank you. I can run MSBuild.exe from the command line and it doesn’t immediately fail. I’m a Linux guy, and I’ve never used MSBuild before. I don’t know how to tell if it’s fully working. Can you suggest a few command-line options for MSBuild.exe to verify that it was installed and working properly?

For example, when cmake tries to run MSBuild.exe, what command-line arguments does to use?

What should VCTargetsPath be set to? Should the user (me) set that explicitly? Or should it be set by the system somewhere?

Is anybody going to help me resolve this? Should I submit a bug report?

The general steps would be to:
Open Visual Studio
Generate a new project with the Console App project (Prints “hello world” to console)
Open the “Developer Command Prompt”
Navigate to where the project .sln was created
Run MSbuild.exe ConsoleApplication1.sln
Watch it build the solution.

This is what I did for Visual Studio 2019 to run MSBuild.exe.

How does one Open the “Developer Command Prompt”?

I have VisualStudio 2017. There is no “Developer Command Prompt”.

I feel like I did my part. I created the minimal cmake configuration that fails. I think you should either tell me what I did was wrong, or cmake is broken and that should be fixed. It should be easy from here.

It is called “Developer Command Prompt for VS 2017”, you can normally find it under Start > Visual Studio 2017 > Developer Command Prompt for VS 2017.

If you really don’t have it, then maybe some required components of VS 2017 are not installed. Please start “Visual Studio Installer”, click on “Modify” and make sure that the “Visual C++ core desktop features” component of the “Desktop development with C++” workload is installed (on the right side).

I hope this helps.

Okay, thanks for your help. I found the developer prompt. And I got the simple ConsoleApp program to compile with no errors. I’m not sure what this accomplishes.

After following the above instructions for the ConsoleAPp, I tried to run cmake on my simple CMakeLists.txt that had been giving me problems. Now it works. I did nothing different.

I guess this means my problem is “solved”. Thank everyone for the help.