简体   繁体   中英

Running multiple exec tasks in parallel

I am batching multiple exec tasks in the build process. Each execution takes around one minute to complete, so I would like to run them in parallel to improve overall build performance.

The target that run multiple exec tasks:

<Target Name="CreatePackages" DependsOnTargets="Build" AfterTargets="Build">
  <Exec Command="SomeExecutable.exe %(SomeGroup.Location) </Exec>
</Target>

The ItemGroup definition:

<ItemGroup>
  <SomeGroup Include="Production">
    <Location>SomePath/Production</Location>
  </SomeGroup>
  <SomeGroup Include="Test">
    <Location>SomePath/Test</Location>
  </SomeGroup>
  <SomeGroup Include="Development">
    <Location>SomePath/Development</Location>
  </SomeGroup>
</ItemGroup>

How do I run these exec tasks in parallel?

MSBuild doesn't parallelize on task or target level, but on project level only. You choices are to wrap each individual location in a target and call project itself in parallel (messy), or to write a custom task with TPL ( System.Threading.Tasks.Parallel ) and Microsoft.Build.Tasks.Exec or System.Diagnostics.Process (easy), or try YieldDuringToolExecution (technically not parallelization, but other tasks would wait less).

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