【问题标题】:How to build project in multiple configurations to automate the build process?如何以多种配置构建项目以自动化构建过程?
【发布时间】:2021-01-21 11:50:48
【问题描述】:
我有一个解决方案,其中包含一个原生项目。要使主项目正常工作,应采取以下步骤:
- 本机项目必须在 Release/x86 配置中构建
- 本机项目必须在 Release/x64 配置中构建
- 必须构建所有 .NET 项目
- 第 1 步和第 2 步中的二进制文件都必须放在主项目的输出文件夹中。
有没有办法配置项目,以便所有这些步骤都发生在只需选择“构建 | 全部重建”时?我知道批量构建选项,但我仍然需要手动执行第 4 步。
【问题讨论】:
标签:
visual-studio
msbuild
【解决方案1】:
我认为你必须use msbuild script 来构建你的项目,而不是 VS IDE。脚本更灵活,可以实现您的要求。
1) 创建一个名为 build.proj 的新文件,然后在该文件中添加以下内容:
<Project>
<ItemGroup>
<!--include all c# csproj files to build these projects all at once-->
<NetProjectFile Include="**\*.csproj" />
<!--include the c++ proj files-->
<NativeProjectFile Include="**\*.vcxproj" />
</ItemGroup>
<Target Name="Build">
<MSBuild Projects="@(NetProjectFile)" Targets="Restore;Build" Properties="Configuration=Debug;Platform=AnyCPU"/>
<!--OutDir is the path of the execute file ,pdb.... if you also want the intermediate files to be in the same folder, you should also use IntDir -->
<MSBuild Projects="@(NativeProjectFile)" Targets="Build" Properties="Configuration=Release;Platform=x86;OutDir=xxx\xxx\"/>
<MSBuild Projects="@(NativeProjectFile)" Targets="Build" Properties="Configuration=Release;Platform=x64;OutDir=xxx\xxx\"/>
</Target>
</Project>
3) 只需运行msbuild build.proj -t:Build 即可获得您想要的。