简体   繁体   中英

Force msbuild to build a project which is unselected in solution config

I use msbuild at command line to build a generated solution file:

msbuild /p:Configuration=Release /p:Platform=Win32 build\zlib\vc-9.0\x86\zlib.sln

The problem is that the solution generated by cmake has a project INSTALL which is not built by default.

minigzip:
  Die Datei "c:\Library\build\zlib\vc-9.0\x86\minigzip.tmp_Release_Win32.vcproj
  " wird gelöscht.
ALL_BUILD:
  Die Datei "c:\Library\build\zlib\vc-9.0\x86\ALL_BUILD.tmp_Release_Win32.vcpro
  j" wird gelöscht.
INSTALL:
  The project "INSTALL" is not selected for building in solution configuration
  "Release|Win32".
Done Building Project "c:\Library\build\zlib\vc-9.0\x86\zlib.sln" (default targ
ets).


Build succeeded.
    0 Warning(s)
    0 Error(s)

How can I force the target INSTALL to be build without manually open the soultion and set the checkbox for the config?

One solution is to call the vcproj file directly (as I did here)

msbuild /p:Configuration=Release /p:Platform=Win32 build\zlib\vc-9.0\x86\INSTALL.vcproj

but this prints the warning

Microsoft (R)-Buildmodul, Version 3.5.30729.6387
[Microsoft .NET Framework, Version 2.0.50727.6400]
Copyright (C) Microsoft Corporation 2007. Alle Rechte vorbehalten.

Build started 06.07.2013 17:07:57.
Project "c:\Library\build\zlib\vc-9.0\x86\INSTALL.vcproj" on node 0 (default ta
rgets).
c:\Library\build\zlib\vc-9.0\x86\INSTALL.vcproj : warning MSB4098: MSBuild is i
nvoking VCBuild to build this project. Project-to-project references between VC
++ projects (.VCPROJ) and C#/VB/VJ# projects (.CSPROJ, .VBPROJ, .VJSPROJ) are n
ot supported by the command-line build systems when building stand-alone VC++ p
rojects. Projects that contain such project-to-project references will fail to
build. Please build the solution file containing this project instead.
Done Building Project "c:\Library\build\zlib\vc-9.0\x86\INSTALL.vcproj" (defaul
t targets).


Build succeeded.

As you can see, the build succeeded. I'm able to ensure the correct build by calling the solution first, but I want to force the solution to build the project INSTALL, too.

Any ideas?

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

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 .

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

最简单的方法是直接构建项目,但不要忘记指定配置和平台。

msbuild /p:Configuration=Release /p:Platform=Win32 INSTALL.vcxproj

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM