在针对多个平台的解决方案中构建Visual Studio C ++项目 [英] Build visual studio C++ project within solution for multiple platforms

查看:64
本文介绍了在针对多个平台的解决方案中构建Visual Studio C ++项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Visual Studio solution that contains multiple C# projects and a C++ project.

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

The C++ project is properly configured to build both for x64 and win32 (has separate output directories, proper binaries referred for 32 and 64 and so on) and default configuration is x64. C# projects are configured for Any CPU.

在构建整个解决方案时,如何配置我的解决方案以同时为x64和Win32构建C ++项目?

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

P.S .:在这种情况下,批处理构建将无法完成,因为我需要以任何人克隆存储库的方式进行配置,而无需进行任何其他设置即可

P.S.: Batch build won't do the job for this case because I need to configure it in a way anyone clones the repo will build properly without any additional settings

推荐答案

如何配置我的解决方案以为两个x64都构建C ++项目和整个构建解决方案时使用win32?

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

请使用批处理构建来构建您的解决方案.

Please use Batch Build to build your solution.

1):首先右键单击您的解决方案,然后选择批处理构建.

1) First Right-click on your solution and choose Batch Build.

2)其次,检查要构建的C ++项目.然后,您可以检查项目的64位和32位,还可以为 Configuration 选择 Debug Release .最后,单击生成"或重新生成"以同时生成不同版本的输出文件.

2) Second, check the C++ project which you want to build. You can then check both 64-bit and 32-bit for the project, and you can also select Debug or Release for the Configuration. Finally, click Build or Rebuild to generate different versions of the output files at the same time.

3)完成后,请打开解决方案文件夹.在我这边, Debug Release 文件夹仅用于 32位,而 x64 文件夹仅用于 64位.

3) When you finish, please open the solution folder. In my side, Debug or Release folder is just for 32-bit while x64 folder is just for 64-bit.

更新1

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

Since you do not want to config VS settings and then use Batch Build, l think you can use custom build target in the xxxx.vcxproj file.

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

Please add these targets into xxxx.vcxproj of all C++ Projects in the whole solution.

<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>

这些目标取决于 Build Clean 目标.因此,当您构建项目时,它们将始终在以后执行,并将项目构建到其他版本中.

These targets depends on Build or Clean target. So when you build the project, they will always execute later and build the project into the other version.

此外,此方法与您的解决方案相关,因此当其他人克隆您的解决方案时,可以直接从您的脚本进行构建,也可以在VS IDE中单击构建,然后看到 x64 x86 版本.

Besides, this method is tied to your solution, so when someone else clones your solution, Build directly from your script or click Build in VS IDE and then you see the x64 and x86 versions of the files in the solution.

希望它可以为您提供帮助.

Hope it could help you.

这篇关于在针对多个平台的解决方案中构建Visual Studio C ++项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆