gregmac / MSBuild.CallTargetsParallel

A task to invoke parallel targets from MSBuild scripts
BSD 2-Clause "Simplified" License
1 stars 0 forks source link

MSBuild CallTargetsParallel

This is an MSBuild task to invoke multiple targets in parallel. It invokes a new instance of msbuild for each target.

Use

Simple target invocation

A simple use is:

<CallTargetsParallel Targets="Target1;Target2" GlobalProperties="PropertyName1;PropertyName2" />

Runs Target1 and Target2 in this project file, passing along the current values of the properties PropertyName1 and PropertyName2.

Installation

Include the CallTargetsParallel.tasks file somewhere in your project, then in the MSBuild file include the line:

<Import Project="CallTargetsParallel.tasks"/>

All features

<ItemGroup>
    <ParallelTargets Include="_global">
        <Property1>value1</Property1>
    </ParallelTargets>
    <ParallelTargets Include="Target1">
        <Property2>value2</Property2> 
    </ParallelTargets>
    <ParallelTargets Include="TargetTwo">
        <Targets>Target2</Targets>
        <Property1>some "value"</Property1>
    </ParallelTargets>
    <ParallelTargets Include="DualExample">
        <Targets>Target1;Target2</Targets>
    </ParallelTargets>
    <ParallelTargets Include="OtherProject">
        <MSBuildFile>myproject.proj</MSBuildFile>
        <Targets>Build</Targets>
        <Property3>$(Property3)</Property3>
    </ParallelTargets>
</ItemGroup>
<CallTargetsParallel Targets="@(ParallelTargets)" GlobalProperties="Property5" />

This will invoke 4 msbuild instances in parallel:

Item definitions:

Limitations:

Inspiration

It's quite similar to the MSBuildExtensionPack Parallel task (http://www.msbuildextensionpack.com/help/4.0.8.0/html/23e4198a-c266-e8a3-4aea-7cf131a0837c.htm) but differs in the way it is invoked, making it significantly easier to pass existing properties without worrying about escaping values for command-line execution. I wrote this because I was trying to use parallel tasks in a complex project, and MSBuildExtensionPack's implementation meant I had giant easy-to-mess-up blocks of parameters to be passed to each invocation, and it quickly became unreadable.

License

"New" BSD: http://opensource.org/licenses/bsd-license.php