强制msbuild构建一个在解决方案配置中未选中的项目

时间:2013-07-06 15:21:19

标签: visual-studio msbuild cmake

我在命令行使用msbuild来构建生成的解决方案文件:

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

问题是cmake生成的解决方案有一个项目INSTALL,它不是默认构建的。

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)

如何在不手动打开灵魂的情况下强制构建目标INSTALL并设置配置的复选框?

一种解决方案是直接调用vcproj文件(就像我在这里所做的那样)

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

但是会打印警告

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.

如您所见,构建成功。我可以通过首先调用解决方案来确保正确的构建,但我想强制解决方案来构建项目INSTALL。

有什么想法吗?

4 个答案:

答案 0 :(得分:10)

据我所知,这是不可能的。查看msbuild的命令行选项和解决方案文件,没有什么可以支持它。但是,既然您正在使用cmake,您可以使用它来为您构建所有内容,而无需手动执行。我发现this thread基本上和你一样问了同样的问题,并且使用了这个想法的正确语法我已经把它作为评论:

cmake --build . --target install

进一步看,从devenv cmmand行选项看来它确实具有您所追求的功能。这会强制构建给定项目,即使它未在Configuration Manager中启用:

devenv build\zlib\vc-9.0\x86\zlib.sln /Build Release /project INSTALL

答案 1 :(得分:4)

stijn's answer是通过cmake构建目标的“惯用”方式。

但请注意,MSbuild可以构建解决方案文件项目文件。您也可以拨打msbuild zlib.sln

,而不是拨打msbuild ALL_BUILD.vcxproj

同样,您可以拨打msbuild INSTALL.vcxproj

答案 2 :(得分:2)

使用CMake版本3.2.2生成的解决方案,确实无法通过解决方案从msbuild构建INSTALL目标。根本原因是,对于INSTALL目标,解决方案仅包含类似GlobalSection(ProjectConfigurationPlatforms)部分中的条目:

    {11C4D30A-3B6A-4350-BD7D-B343F3A843C0}.Debug|Win32.ActiveCfg = Debug|Win32

如果您添加以下条目:

    {11C4D30A-3B6A-4350-BD7D-B343F3A843C0}.Debug|Win32.Build.0 = Debug|Win32

然后可以使用如下命令构建INSTALL目标:

    msbuild <pathToProject>.sln /target:INSTALL

答案 3 :(得分:0)

最简单的方法是直接构建项目,但不要忘记指定Configuration和Platform。

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