如何使用BatchBuild并行构建多个C ++ Visual Studio v2015 +配置 [英] How can you build multiple C++ visual studio v2015+ configurations in parallel using BatchBuild

查看:178
本文介绍了如何使用BatchBuild并行构建多个C ++ Visual Studio v2015 +配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对IDE非常熟悉(23年),但对MSBuild一点都不了解.

I am very familiar with the IDE (23 years), but not at all with MSBuild.

我已阅读并重新阅读

I have read and re-read https://docs.microsoft.com/en-gb/visualstudio/msbuild/building-multiple-projects-in-parallel-with-msbuild?view=vs-2015 about making MSBuild build multiple configurations in parallel, but I don't understand how to hook it to "batch build" (or infact MSBuild, which would be my lat resort).

为了描述我想要实现的目标,如果我将项目的30个副本全部都指向一个具有相同配置的同一代码,那么我可以批量构建它们,并且它们将充分利用许多内核,其中一个具有30种配置项目,它们都是串行构建的,因此对CPU内核的使用非常差.

To describe what I want to achieve differently, if I mad 30 copies of the project all pointing to the same code with one config each I could then batch build and they would make good use of many cores, with 30 configurations of one project, they all build serially making very poor use of CPU cores.

另一方面,我不明白为什么IDE可以选择并行构建多个项目和多个文件的选项,但没有多个配置.

On a side note, I don't understand why the IDE has options for building multiple projects and multiple files in parallel, but not multiple configurations.

推荐答案

另一方面,我不明白为什么IDE有以下选项: 并行构建多个项目和多个文件,但不能并行构建 多种配置.

On a side note, I don't understand why the IDE has options for building multiple projects and multiple files in parallel, but not multiple configurations.

实际上,在VS IDE中,同时

Actually, in VS IDE, Batch Build UI has an option to config the configuration for projects.

但是它可以为项目配置多个configurationPlatform .....,但不能并行处理构建项目.

But it can configure multiple configuration, Platform..... for projects but does not process build projects in parallel.

建议

我建议您可以使用msbuild脚本,然后使用 MSBuild命令行来运行具有多个平台的多个项目.

I suggest you could use a msbuild script to and then use MSBuild Command Line to run several projects with multiple platforms.

1)创建一个名为test.proj

2)在其中添加以下内容:

2) add these in it:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <ProjectFile Include="C:\xxxx\ConsoleApplication1.vcxproj">
    <Properties>Configuration=Release</Properties>
    </ProjectFile>
      <ProjectFile Include="C:\xxx\ConsoleApplication1.vcxproj">
          <Properties>Configuration=Debug</Properties>
      </ProjectFile>

      <ProjectFile Include="C:\xxx\ConsoleApplication1.vcxproj">
          <Properties>Configuration=xxx</Properties>
      </ProjectFile>
      .....
      // add any configuration like this and remember to include the related vcxproj and even the same vcxproj has to be written for different configurations.
  </ItemGroup>

    <Target Name="ParelBuild"> 
        <MSBuild Projects="@(ProjectFile)" BuildInParallel="true" Targets="Build" />
    </Target>
</Project>

请参见类似问题.

3) 注意:Developer Command Prompt for VS2015没有显示并行构建的功能,我感到很困惑.

3) Note: Developer Command Prompt for VS2015 does not show the features of parallel build and I feel quite confused.

所以,要进行并行构建,建议您下载用于VS2019的构建工具,可以与VS2019分开安装,并支持较低版本的MSBuild 14.0.我已经成功测试了.

So to parallel build, I suggest you could download Build Tool for VS2019 which can be installed separately from VS2019 and supports lower versions of MSBuild 14.0. And I have tested successfully.

(下载链接位于所有下载-> Visual Studio 2019的工具下)

(the download link is under All Downloads-->Tools for Visual Studio 2019)

4)使用此MSBuild命令行进行构建:

4) use this MSBuild command line to build:

msbuild test.proj -t:ParelBuild -v:normal -m:30

效果如下:

更新1

在不同时间建立自己的项目组合,您可以尝试以下方法:

Build your own portfolio of projects at different times and you can try these:

 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ItemGroup>
        <ProjectFile Include="C:\xxxx\ConsoleApplication1.vcxproj">
        <Properties>Configuration=Release</Properties>
        </ProjectFile>
          <ProjectFile Include="C:\xxx\ConsoleApplication1.vcxproj">
              <Properties>Configuration=Debug</Properties>
          </ProjectFile>

          <ProjectFile Include="C:\xxx\ConsoleApplication1.vcxproj">
              <Properties>Configuration=xxx</Properties>
          </ProjectFile>
          .....
          // add any configuration like this and remember to include the related vcxproj and even the same vcxproj has to be written for different configurations.
      </ItemGroup>

<ItemGroup>
        <ProjectFile1 Include="C:\xxxx\ConsoleApplication1.vcxproj">
        <Properties>Configuration=Release</Properties>
        </ProjectFile1>
          <ProjectFile1 Include="C:\xxx\xxx.sln">
              <Properties>Configuration=Debug</Properties>
          </ProjectFile1>
       ........     
      </ItemGroup>

        <Target Name="ParelBuild1"> 
            <MSBuild Projects="@(ProjectFile1)" BuildInParallel="true" Targets="Build" />
        </Target>
    </Project>

然后首先一次构建ParelBuild目标:

Then first build the ParelBuild target at one time:

msbuild test.proj -t:ParelBuild 

之后,在另一时间执行以下操作:

After it, at another time, execute this:

 msbuild test.proj -t:ParelBuild1 

这使您可以在不同的时间点并行执行组合的项目.

This allows you to execute combined projects in parallel at different points in time.

这篇关于如何使用BatchBuild并行构建多个C ++ Visual Studio v2015 +配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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