.net - 在多个平台的解决方案中构建 Visual Studio C++ 项目

标签 .net visual-studio visual-c++ build msbuild

我有一个 Visual Studio 解决方案,其中包含多个 C# 项目和一个 C++ 项目。

C++ 项目已正确配置为针对 x64 和 win32 进行构建(具有单独的输出目录、针对 32 和 64 引用的正确二进制文件等),并且默认配置为 x64。 C# 项目针对任何 CPU 进行配置。

在构建整个解决方案时,如何配置我的解决方案以构建适用于 x64 和 win32 的 C++ 项目?

P.S.:批量构建无法完成这种情况的工作,因为我需要以任何人克隆存储库都可以正确构建的方式进行配置,而无需任何其他设置

最佳答案

How can I configure my solution to build the C++ project for both x64 and win32 when building the entire solution?

请使用批量构建来构建您的解决方案。

1) 首先右键单击您的解决方案并选择批量构建

2) 其次,检查您要构建的 C++ 项目。然后您可以检查项目的 64 位和 32 位,还可以选择 DebugRelease用于配置。最后,单击“Build”或“Rebuild”以同时生成不同版本的输出文件。

enter image description here

3) 完成后,请打开解决方案文件夹。在我身边,DebugRelease文件夹仅适用于 32 位,而 x64文件夹仅适用于64位

enter image description here

更新1

由于您不想配置 VS 设置然后使用批量构建,我认为您可以在 xxxx.vcxproj 中使用自定义构建目标文件。

请将这些目标添加到 xxxx.vcxproj整个解决方案中的所有 C++ 项目。

<Target Name="BuildFunction" AfterTargets="Build">
    <MSBuild Condition="'$(Platform)'=='Win32'" Projects="$(MSBuildProjectFile)" Properties="Platform=x64;PlatFormTarget=x64" RunEachTargetSeparately="true"  />
    <MSBuild Condition="'$(Platform)'=='x64'"   Projects="$(MSBuildProjectFile)" Properties="Platform=Win32;PlatFormTarget=x86" RunEachTargetSeparately="true" />
  </Target>

  <Target Name="CleanAll" AfterTargets="Clean">
    <MSBuild Condition="'$(Platform)'=='Win32'" Projects="$(MSBuildProjectFile)" Targets="Clean" Properties="Platform=x64;PlatFormTarget=x64" RunEachTargetSeparately="true"  />
    <MSBuild Condition="'$(Platform)'=='x64'"   Projects="$(MSBuildProjectFile)" Targets="Clean" Properties="Platform=Win32;PlatFormTarget=x86" RunEachTargetSeparately="true" />

  </Target>

这些目标取决于BuildClean目标。因此,当您构建项目时,它们总是会稍后执行并将项目构建为其他版本。

此外,此方法与您的解决方案相关联,因此当其他人克隆您的解决方案时,直接从您的脚本构建或单击 VS IDE 中的构建,然后您会看到 x64x86解决方案中文件的版本。

希望对您有帮助。

关于.net - 在多个平台的解决方案中构建 Visual Studio C++ 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59827393/

相关文章:

c++ - 错误 C2678 : binary '!=' : no operator found

c# - ASP.NET 页面上的 Reporting Services 呈现错误

node.js - Angular2 Visual Studio 2017 MVC : Uncaught TypeError: System. 配置不是一个函数

c++ - 微软 C++ 编译器 : how to disable auto-vectorization with/O2?

c# - 如何在双击文件后立即附加调试器?

javascript - Visual Studio、ASP.Net (.Net Framework) 以及在项目中包含 NuGet 安装的包

c++ - 错误 LNK2019 : unresolved external symbol

c# - StackOverFlowException - 但显然没有递归/无限循环

c# - 写入流时计算哈希

c# - LINQ 查询中的 MySqlDateTime