Force msbuild to build a project which is unselected in solution config
As far as I know this is not possible. Looking at msbuild's command line options and in the solution file, there's nothing to support it. But since you're using cmake, you can use it to to build everything for you without having to do it manually. I found this thread which basically asks the same question as you, and has the correct syntax using the idea already I put it the comment:
cmake --build . --target install
Looking somewhat further, from the devenv
cmmand line options it seems it does have the functionality you're after. This forces a build of the given project even if it's not enabled in the Configuration Manager:
devenv build\zlib\vc-9.0\x86\zlib.sln /Build Release /project INSTALL
Using the solution generated by CMake version 3.2.2, it is indeed not possible to build the INSTALL target from msbuild through the solution. The root cause is that for the INSTALL target, the solution only contains entries like those in the section GlobalSection(ProjectConfigurationPlatforms):
{11C4D30A-3B6A-4350-BD7D-B343F3A843C0}.Debug|Win32.ActiveCfg = Debug|Win32
If you add entries like these:
{11C4D30A-3B6A-4350-BD7D-B343F3A843C0}.Debug|Win32.Build.0 = Debug|Win32
Then it becomes possible to build the INSTALL target with a command like this:
msbuild <pathToProject>.sln /target:INSTALL
stijn's answer is the "idiomatic" way of building targets through cmake.
Note however that MSbuild can build both solution files and project files. Instead of calling msbuild zlib.sln
, you could also call msbuild ALL_BUILD.vcxproj
.
Similarly, you can call msbuild INSTALL.vcxproj
.