简体   繁体   中英

How can you build multiple C++ visual studio v2015+ configurations in parallel using BatchBuild

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

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.

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.

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.

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

在此处输入图像描述

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

Suggestion

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

1) Create a file called test.proj

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>

See this similar issue .

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

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.

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

4) use this MSBuild command line to build:

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

The effect is as follows:

在此处输入图像描述

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

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.

The answer is that you can't do what I wanted, but there is a workaround by Parry Qian-MSFT. There is an open request on https://developercommunity.visualstudio.com/ , so I have upvoted that in the hopes that it can be easily integrated into a future version of Visual Studio. I'm sure it could be a plugin, but I don't have time to investigate that at this time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM