使用msbuild.exe

时间:2019-10-11 01:49:13

标签: visual-studio msbuild visual-studio-2017

我有一个包含n-C++ projects的VS解决方案。有什么方法可以让msbuild.exe通过命令行编译项目的特定子集?

msbuild.exe foo.sln /thisFlagWouldBeCool:project1;project2

我为目标尝试了/t标志,但是由于目标不是项目,所以似乎没有做到这一点?

1 个答案:

答案 0 :(得分:0)

1。请参阅How to: Build specific targets in solutions by using MSBuild.exe。如状态所示,您可以使用以下命令:

msbuild SlnFolders.sln -target:NotInSlnfolder:Rebuild;NewFolder\InSolutionFolder:Clean

更具体地说,如果您在同一解决方案(Test.sln)中有Project A, B, C,仅要构建A和B,则可以使用以下命令:

msbuild Test.sln /t:A;B /p:Configuration="xx" /p:Platform="xx"

注意:要以这种方式进行构建,我们应确保在A.xxproj文件中定义了B.xxprojxx.sln。至少对于VS,如果我们创建一个新的Project C,则只有在单击xx.sln按钮之后,save all才会更新。

2。这是适用于某些特定场景的另一个方向:

我们可以右键单击VS中的“解决方案”节点,选择add project=>empty project将一个空项目添加到解决方案中,我们将其命名为MyBuildTool项目。将其卸载以编辑其MyBuildTool.vcxproj文件,将这种脚本添加到脚本的底部(在“项目”标签中):

  <!--If you're trying to build subset  of the solution, any build the projects with different settings-->
  <Target Name="CustomBuild" AfterTargets="build">
    <MSBuild Projects="..\**\B2.vcxproj" Properties="Configuration=Debug;Platform=x64;OutDir=xxx"/>
    <MSBuild Projects="..\**\A2.vcxproj" Properties="Configuration=Release"/>
    ...
  </Target>

  <!--If you're building several projects in same settings-->
  <Target Name="CustomBuild" AfterTargets="build">
    <ItemGroup>
      <ProjectsToBuild Include="..\**\A1.vcxproj"/>
      <ProjectsToBuild Include="..\**\B1.vcxproj"/>
    </ItemGroup>
    <MSBuild Projects="@(ProjectsToBuild)" Properties="Configuration=Debug" BuildInParallel="true"/>
  </Target>
</Project>

然后MyBuildTool.vcxproj现在是我们的构建脚本,如果在某些特定情况下我们需要构建多个项目,则只需运行命令msbuild.exe MyBuildTool.vcxproj。这取决于MSBuild Task的用法。

相关问题