|
2 | 2 | title: "MSBuild Batching | Microsoft Docs"
|
3 | 3 | ms.date: "11/04/2016"
|
4 | 4 | ms.topic: "conceptual"
|
5 |
| -helpviewer_keywords: |
| 5 | +helpviewer_keywords: |
6 | 6 | - "batching [MSBuild]"
|
7 | 7 | - "MSBuild, batching"
|
8 | 8 | ms.assetid: d35c085b-27b8-49d7-b6f8-8f2f3a0eec38
|
9 | 9 | author: mikejo5000
|
10 | 10 | ms.author: mikejo
|
11 | 11 | manager: jillfra
|
12 |
| -ms.workload: |
| 12 | +ms.workload: |
13 | 13 | - "multiple"
|
14 | 14 | ---
|
15 | 15 | # MSBuild batching
|
16 |
| -[!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] has the ability to divide item lists into different categories, or batches, based on item metadata, and run a target or task one time with each batch. |
17 |
| - |
18 |
| -## Task batching |
19 |
| - Task batching allows you to simplify your project files by providing a way to divide item lists into different batches and pass each of those batches into a task separately. This means that a project file only needs to have the task and its attributes declared once, even though it can be run several times. |
20 |
| - |
21 |
| - You specify that you want [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] to perform batching with a task by using the %(\<ItemMetaDataName>) notation in one of the task attributes. The following example splits the `Example` item list into batches based on the `Color` item metadata value, and passes each of the batches to the `MyTask` task separately. |
22 |
| - |
| 16 | +[!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] has the ability to divide item lists into different categories, or batches, based on item metadata, and run a target or task one time with each batch. |
| 17 | + |
| 18 | +## Task batching |
| 19 | +Task batching allows you to simplify your project files by providing a way to divide item lists into different batches and pass each of those batches into a task separately. This means that a project file only needs to have the task and its attributes declared once, even though it can be run several times. |
| 20 | + |
| 21 | +You specify that you want [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] to perform batching with a task by using the %(\<ItemMetaDataName>) notation in one of the task attributes. The following example splits the `Example` item list into batches based on the `Color` item metadata value, and passes each of the batches to the `MyTask` task separately. |
| 22 | + |
23 | 23 | > [!NOTE]
|
24 |
| -> If you do not reference the item list elsewhere in the task attributes, or the metadata name may be ambiguous, you can use the %(\<ItemCollection.ItemMetaDataName>) notation to fully qualify the item metadata value to use for batching. |
25 |
| - |
26 |
| -```xml |
27 |
| -<Project |
28 |
| - xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
29 |
| - |
30 |
| - <ItemGroup> |
31 |
| - <Example Include="Item1"> |
32 |
| - <Color>Blue</Color> |
33 |
| - </Example> |
34 |
| - <Example Include="Item2"> |
35 |
| - <Color>Red</Color> |
36 |
| - </Example> |
37 |
| - </ItemGroup> |
38 |
| - |
39 |
| - <Target Name="RunMyTask"> |
40 |
| - <MyTask |
41 |
| - Sources = "@(Example)" |
42 |
| - Output = "%(Color)\MyFile.txt"/> |
43 |
| - </Target> |
44 |
| - |
45 |
| -</Project> |
46 |
| -``` |
47 |
| - |
48 |
| - For more specific batching examples, see [Item metadata in task batching](../msbuild/item-metadata-in-task-batching.md). |
49 |
| - |
50 |
| -## Target batching |
51 |
| - [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] checks if the inputs and outputs of a target are up-to-date before it runs the target. If both inputs and outputs are up-to-date, the target is skipped. If a task inside of a target uses batching, [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] needs to determine if the inputs and outputs for each batch of items is up-to-date. Otherwise, the target is executed every time it is hit. |
52 |
| - |
53 |
| - The following example shows a `Target` element that contains an `Outputs` attribute with the %(\<ItemMetaDataName>) notation. [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] will divide the `Example` item list into batches based on the `Color` item metadata, and analyze the timestamps of the output files for each batch. If the outputs from a batch are not up-to-date, the target is run. Otherwise, the target is skipped. |
54 |
| - |
55 |
| -```xml |
56 |
| -<Project |
57 |
| - xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
58 |
| - |
59 |
| - <ItemGroup> |
60 |
| - <Example Include="Item1"> |
61 |
| - <Color>Blue</Color> |
62 |
| - </Example> |
63 |
| - <Example Include="Item2"> |
64 |
| - <Color>Red</Color> |
65 |
| - </Example> |
66 |
| - </ItemGroup> |
67 |
| - |
68 |
| - <Target Name="RunMyTask" |
69 |
| - Inputs="@(Example)" |
70 |
| - Outputs="%(Color)\MyFile.txt"> |
71 |
| - <MyTask |
72 |
| - Sources = "@(Example)" |
73 |
| - Output = "%(Color)\MyFile.txt"/> |
74 |
| - </Target> |
75 |
| - |
76 |
| -</Project> |
77 |
| -``` |
78 |
| - |
79 |
| - For another example of target batching, see [Item metadata in target batching](../msbuild/item-metadata-in-target-batching.md). |
80 |
| - |
81 |
| -## Property functions using metadata |
82 |
| - Batching can be controlled by property functions that include metadata. For example, |
83 |
| - |
84 |
| - `$([System.IO.Path]::Combine($(RootPath),%(Compile.Identity)))` |
85 |
| - |
86 |
| - uses <xref:System.IO.Path.Combine%2A> to combine a root folder path with a Compile item path. |
87 |
| - |
88 |
| - Property functions may not appear within metadata values. For example, |
89 |
| - |
90 |
| - `%(Compile.FullPath.Substring(0,3))` |
91 |
| - |
92 |
| - is not allowed. |
93 |
| - |
94 |
| - For more information about property functions, see [Property functions](../msbuild/property-functions.md). |
95 |
| - |
96 |
| -## See also |
97 |
| - [ItemMetadata element (MSBuild)](../msbuild/itemmetadata-element-msbuild.md) |
98 |
| - [MSBuild concepts](../msbuild/msbuild-concepts.md) |
99 |
| - [MSBuild reference](../msbuild/msbuild-reference.md) |
100 |
| - [Advanced concepts](../msbuild/msbuild-advanced-concepts.md) |
| 24 | +> If you do not reference the item list elsewhere in the task attributes, or the metadata name may be ambiguous, you can use the %(\<ItemCollection.ItemMetaDataName>) notation to fully qualify the item metadata value to use for batching. |
| 25 | +
|
| 26 | +```xml |
| 27 | +<Project |
| 28 | + xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 29 | + |
| 30 | + <ItemGroup> |
| 31 | + <Example Include="Item1"> |
| 32 | + <Color>Blue</Color> |
| 33 | + </Example> |
| 34 | + <Example Include="Item2"> |
| 35 | + <Color>Red</Color> |
| 36 | + </Example> |
| 37 | + </ItemGroup> |
| 38 | + |
| 39 | + <Target Name="RunMyTask"> |
| 40 | + <MyTask |
| 41 | + Sources = "@(Example)" |
| 42 | + Output = "%(Color)\MyFile.txt"/> |
| 43 | + </Target> |
| 44 | + |
| 45 | +</Project> |
| 46 | +``` |
| 47 | + |
| 48 | +For more specific batching examples, see [Item metadata in task batching](../msbuild/item-metadata-in-task-batching.md). |
| 49 | + |
| 50 | +## Target batching |
| 51 | +[!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] checks if the inputs and outputs of a target are up-to-date before it runs the target. If both inputs and outputs are up-to-date, the target is skipped. If a task inside of a target uses batching, [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] needs to determine if the inputs and outputs for each batch of items is up-to-date. Otherwise, the target is executed every time it is hit. |
| 52 | + |
| 53 | +The following example shows a `Target` element that contains an `Outputs` attribute with the %(\<ItemMetaDataName>) notation. [!INCLUDE[vstecmsbuild](../extensibility/internals/includes/vstecmsbuild_md.md)] will divide the `Example` item list into batches based on the `Color` item metadata, and analyze the timestamps of the output files for each batch. If the outputs from a batch are not up-to-date, the target is run. Otherwise, the target is skipped. |
| 54 | + |
| 55 | +```xml |
| 56 | +<Project |
| 57 | + xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 58 | + |
| 59 | + <ItemGroup> |
| 60 | + <Example Include="Item1"> |
| 61 | + <Color>Blue</Color> |
| 62 | + </Example> |
| 63 | + <Example Include="Item2"> |
| 64 | + <Color>Red</Color> |
| 65 | + </Example> |
| 66 | + </ItemGroup> |
| 67 | + |
| 68 | + <Target Name="RunMyTask" |
| 69 | + Inputs="@(Example)" |
| 70 | + Outputs="%(Color)\MyFile.txt"> |
| 71 | + <MyTask |
| 72 | + Sources = "@(Example)" |
| 73 | + Output = "%(Color)\MyFile.txt"/> |
| 74 | + </Target> |
| 75 | + |
| 76 | +</Project> |
| 77 | +``` |
| 78 | + |
| 79 | +For another example of target batching, see [Item metadata in target batching](../msbuild/item-metadata-in-target-batching.md). |
| 80 | + |
| 81 | +## Property functions using metadata |
| 82 | +Batching can be controlled by property functions that include metadata. For example, |
| 83 | + |
| 84 | +`$([System.IO.Path]::Combine($(RootPath),%(Compile.Identity)))` |
| 85 | + |
| 86 | +uses <xref:System.IO.Path.Combine%2A> to combine a root folder path with a Compile item path. |
| 87 | + |
| 88 | +Property functions may not appear within metadata values. For example, |
| 89 | + |
| 90 | +`%(Compile.FullPath.Substring(0,3))` |
| 91 | + |
| 92 | +is not allowed. |
| 93 | + |
| 94 | +For more information about property functions, see [Property functions](../msbuild/property-functions.md). |
| 95 | + |
| 96 | +## See also |
| 97 | +[ItemMetadata element (MSBuild)](../msbuild/itemmetadata-element-msbuild.md) |
| 98 | +[MSBuild concepts](../msbuild/msbuild-concepts.md) |
| 99 | +[MSBuild reference](../msbuild/msbuild-reference.md) |
| 100 | +[Advanced concepts](../msbuild/msbuild-advanced-concepts.md) |
0 commit comments