【问题标题】:Compile a list of projects with msbuild.exe使用 msbuild.exe 编译项目列表
【发布时间】:2020-02-08 12:09:39
【问题描述】:

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

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

我为目标尝试了/t 标志,但似乎没有这样做,因为目标不是项目?

【问题讨论】:

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


【解决方案1】:

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.xxprojB.xxprojxx.sln 文件中定义。至少对于 VS,如果我们创建一个新的项目 C,在我们点击 save all 按钮之前,xx.sln 不会更新。

2.还有一个适合某些特定场景的方向:

我们可以在VS中右击Solution节点,选择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的用法。

【讨论】:

  • 我确实试过了,但它说目标不存在(但这是项目的名称)
  • 您使用的命令是否与上述问题中的命令相同?稍后我会检查它:)
  • 是的,差不多,它说目标不存在。很奇怪"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" mysolution.sln /t:project1 /p:Configuration="Release" /p:Platform="x64"
  • 在执行命令之前,用记事本打开mysolution.sln,看看xx.sln文件中是否定义了抛出错误信息的project1。我猜您的 xx.sln 在您创建项目后可能不会更新...(全部保存有帮助吗?)
  • 嗯,我可以在slnProject(部分看到项目
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-14
  • 1970-01-01
  • 1970-01-01
  • 2021-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多