Build visual studio C++ project within solution for multiple platforms

做~自己de王妃 提交于 2021-02-17 06:43:10

问题


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

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.

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

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


回答1:


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) First Right-click on your solution and choose Batch Build.

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

Update 1

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.

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>

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.

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.



来源:https://stackoverflow.com/questions/59827393/build-visual-studio-c-project-within-solution-for-multiple-platforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!