
Dividing Several Item Collections into Batches
MSBuild can divide multiple item collections into batches based on the same metadata. This makes it easy to divide different item collections into batches to build multiple assemblies. For example, you could have an item collection of .cs files divided into an application batch and an assembly batch, and an item collection of resource files divided into an application batch and an assembly batch. You could then use batching to pass these item collections into one task and build both the application and the assembly.
Note |
|---|
| If an item collection being passed into a task contains no items with the referenced metadata, every item in that item collection is passed into every batch. |
The following example shows how to divide multiple item collection into batches based on item metadata. The ExampColl and ExampColl2 item collections are each divided into three batches based on the Number item metadata. The presence of %(Number)in the Text attribute notifies MSBuild that batching should be performed. The ExampColl and ExampColl2 item collections are divided into three batches based on the Number metadata, and each batch is passed separately into the task.
<Project
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ExampColl Include="Item1">
<Number>1</Number>
</ExampColl>
<ExampColl Include="Item2">
<Number>2</Number>
</ExampColl>
<ExampColl Include="Item3">
<Number>3</Number>
</ExampColl>
<ExampColl2 Include="Item4">
<Number>1</Number>
</ExampColl2>
<ExampColl2 Include="Item5">
<Number>2</Number>
</ExampColl2>
<ExampColl2 Include="Item6">
<Number>3</Number>
</ExampColl2>
</ItemGroup>
<Target Name="ShowMessage">
<Message
Text = "Number: %(Number) -- Items in ExampColl: @(ExampColl) ExampColl2: @(ExampColl2)"/>
</Target>
</Project> The Message Task task displays the following information:
Number: 1 -- Items in ExampColl: Item1 ExampColl2: Item4
Number: 2 -- Items in ExampColl: Item2 ExampColl2: Item5
Number: 3 -- Items in ExampColl: Item3 ExampColl2: Item6