如何在多个配置中构建项目以自动化构建过程?
How to build project in multiple configurations to automate the build process?
我有一个解决方案,其中包含一个本机项目。为使主项目正常运行,应采取以下步骤:
- 必须在 Release/x86 配置中构建本机项目
- 本机项目必须在 Release/x64 配置中构建
- 必须构建所有 .NET 项目
- 第 1 步和第 2 步的二进制文件都必须放在主项目的输出文件夹中。
有没有一种方法可以配置项目,以便只需选择“构建 | 全部重建”即可完成所有这些步骤?我知道批量构建选项,但我仍然必须手动执行第 4 步。
我认为您必须 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
得到你想要的。
我有一个解决方案,其中包含一个本机项目。为使主项目正常运行,应采取以下步骤:
- 必须在 Release/x86 配置中构建本机项目
- 本机项目必须在 Release/x64 配置中构建
- 必须构建所有 .NET 项目
- 第 1 步和第 2 步的二进制文件都必须放在主项目的输出文件夹中。
有没有一种方法可以配置项目,以便只需选择“构建 | 全部重建”即可完成所有这些步骤?我知道批量构建选项,但我仍然必须手动执行第 4 步。
我认为您必须 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
得到你想要的。