MSBUILD : error MSB1009: Project file does not exist. Switch: ALL_BUILD.vcxproj

I am trying to use CMake to run a series of msbuild commands to build multiple
Visual Studio C++ projects.
I have done this using nmake.
The long term plan is to bring the projects up to date, using latest tools.

OS: Windows 10
Visual Studio 16 2019
Language Visual C++
Command Prompt: x64 Native Tools Command Prompt for VS 2019
as Administrator

cmd line: cmake --build … --config Debug --target ALL_BUILD -G “Visual Studio 16 2019”

CMakeList.txt Chunk:
“C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/msbuild.exe”
“U:/ProjLib/ProjLib.sln” -t:Rebuild -p:Configuration=Debug /p:Platform=“x64” -ds

Microsoft (R) Build Engine version 16.11.0+0538acc04 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : error MSB1009: Project file does not exist.
Switch: ALL_BUILD.vcxproj

I have ran the command from the command directly without CMake.
Works fine.

What am I doing wrong?

You shouldn’t do this as part of CMakeLists.txt via execute_process. It’d be better to defer the build of the project until build time using add_custom_command. Better would be to use ExternalProject or FetchContent.

Cc: @craig.scott

That’s not a valid command line. It looks like you’re trying to combine configuring and building into a single command. You need to configure first, then build. There’s also no need to explicitly specify the target if you want to build the default “all” target. Something more like the following should be more appropriate:

cmake -G “Visual Studio 16 2019” -S . -B path/to/build-dir
cmake --build path/to/build-dir --config Debug

If you need to have your main build trigger a few of these, then ExternlProject does seem more like what you want to be using though.

I have switched to ExternalProject_Add (also tried “ExternalProject_AddStep”)

BUILD_COMMAND msbuild “U:/ProjLib/ProjLib.sln” -t:Rebuild -p:Configuration=Debug /p:Platform=“x64” -ds
COMMENT “Building Project”

I am still having the same problem.

Cmd Line: cmake --build . --config Debug -G “Visual Studio 16 2019” -verbose

Regarding Command Line, I am trying to anything to get this to work.

Also, Is there a way to give a more detailed/verbose output.
I am trying to figure out if:
1) it’s configure problem
2) msbuild problem
3) confirm that it is a cmake only problem.

Simply moving the same failing build command to ExternalProject_Add() isn’t going to help you. Perhaps I misunderstood what you are trying to achieve. Do you already have the Visual Studio project files generated by something other than CMake? Perhaps what you really want is the include_external_msproject() command. I haven’t used it myself, but it looks like it might be relevant to your use case.

As to why the command you’re currently trying to use fails when run from within CMake, maybe you need to set the WORKING_DIRECTORY option when using execute_process(). I wouldn’t be trying to invoke these sub-builds in this way myself, I’d be looking to do it at build time, as Ben suggested. If you’re in luck, include_external_msproject() might give you what you need for this, otherwise look at using add_custom_target() or add_custom_command().

Sorry, I am not being clear.

In nmake, I can do the following:
cd $(MAKEDIR)\Proj1
$(MAKE) $(OPTIONS) Proj1.mak CFG=“Proj1 - Win32 Debug”
cd $(MAKEDIR)\

cd $(MAKEDIR)\Proj2
$(MAKE) $(OPTIONS) Proj2.mak CFG=“Proj2 - Win32 Debug”
cd $(MAKEDIR)\

cd $(MAKEDIR)\WindowProj1
$(MAKE) $(OPTIONS) WindowProj1.mak CFG=“WindowProj1 - Win32 Debug”
cd $(MAKEDIR)\

(continue …)

I want to replace the nmake with cmake, and do the samething.
A makefile that builds multiple Visual Studio projects.
Also, I am upgrading the projects to 64-bit.

I apologize if I am not being clear.

Also, I am still getting the same error:
MSBUILD : error MSB1009: Project file does not exist.
Switch: ALL_BUILD.vcxproj