0

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

I have read and re-read https://learn.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.

Jeaninez - MSFT
  • 3,210
  • 1
  • 5
  • 20
  • I am very grateful for your help, but the answer to how do I use A to do B is not to scrap A and use C instead. C may be a good tool, but it is not an answer. The nearest thing to a positive answer is to upvote the feature and hope it gets into a VS update. – Richard Broadhurst May 19 '20 at 07:24

2 Answers2

1

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.

enter image description here

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:

enter image description here

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.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • Thank you for the complimentary information, but it doesn't answer the question. I need to build different combinations of configurations at different times and so it looks like I would need an MSBuild project for every possible combination of projects. The second problem is that your answer does not include the Solution and so will be missing the Solution information. These and two reasons for wanting the BatchBuild integration. It looks like I might be able to specify the solutions, but I seem to remember not being able to specify solution, project and configuration but haven't tried it. – Richard Broadhurst May 13 '20 at 09:22
  • Actually, you can also define the `xxx.sln` file like `xxx.vcxproj` file:........ and if you want to combine different projects, you can write several build target to execute the build process as you want. – Mr Qian May 13 '20 at 09:28
  • I'm going with this for now, and will investigate how to clean all then build all. I have made a separate .sln with just the projects that need to be built like this, so I can specify the .sln instead of the proj. I got an error about build configuration |BPC which seems to be quite common. This is due to having an environment variable Platform=BPC. I don't know where it came from, so my solution is to run from a .bat file and define it myself in there before running build. – Richard Broadhurst May 13 '20 at 09:51
  • Also, you can put several projects into a sln file and build it like my solution. If you want add the Platform, you can use ` Configuration=Debug;Platform=xxx `. To clean that combined projects, you can also ` `. – Mr Qian May 13 '20 at 10:19
  • You can try my solution and test it. If realize your requirements, you can consider accepting it since it has a workaround. – Mr Qian May 13 '20 at 10:23
  • I am using your workaround for batch building one of the project's configurations in parallel, the rest I am using the built in batch build. I regularly build different configs of different projects from the solution, hence, really wanting a tick box on batch build to batch build in parallel. Most of the work is usually building various configurations for one of the projects. Your solution halves the worst case time for that project, so is nearly always a win. The only answer to the question is "it can't currently be done", but your workaround is very welcome. – Richard Broadhurst May 16 '20 at 07:26
0

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.

  • Since you have your own solution for this issue, I suggest you could mark your answer. – Mr Qian May 18 '20 at 02:54
  • The workaround is helpful, but does not answer the question and is not a replacement for a built in parallel option in the GUI that works with the excellent built in BatchBuild feature. – Richard Broadhurst May 19 '20 at 07:15