You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`<ItemGroup>` section is for specifying files to be included on build, one could use builtin.
55
+
`<ItemGroup>` section is generally for specifying files to be included on build.
56
+
Children under `<ItemGroup>` are not necessarily files, **they can be any list with a name(the tag name) that has items represented as string**.
56
57
Attributes for child items are similar to parameters of item-cmdlet in PowerShell.
57
58
58
-
-`Include`: include items on declaration
59
-
-`Exclude`: exclude items on declaration
60
-
61
59
```xml
62
60
<ItemGroup>
63
-
<CompileInclude="one.cs;three.cs" />
64
-
<CompileExclude="*.fs" />
61
+
<!-- represents a normal list -->
62
+
<!-- child tag with same name are included within same list -->
63
+
<FooListInclude="foo;bar" />
64
+
<FooListInclude="baz;qux" />
65
+
66
+
<MyFileInclude="*.cs"/>
65
67
</ItemGroup>
66
68
```
67
69
70
+
### Item Attributes
71
+
72
+
Item attributes are for controlling how items could be initialized, added and removed to a list
73
+
74
+
-`Include`: include items on declaration
75
+
- use `KeepMetadata` or `RemoveMetadata` to optionally include or exclude metadata from when **creating items by transforming** from another **within a `<Target>`**
76
+
```xml
77
+
<ItemGroup>
78
+
<OldInclude="*"> <!-- [!code highlight] -->
79
+
<Foo>foo</Foo> <!-- [!code highlight] -->
80
+
<Bar>bar</Bar> <!-- [!code highlight] -->
81
+
</Old> <!-- [!code highlight] -->
82
+
</ItemGroup>
83
+
84
+
<Target>
85
+
<ItemGroup>
86
+
<NewInclude="@(Old)"RemoveMetadata="Foo"/> <!-- transform from Old --><!-- [!code highlight] -->
87
+
</ItemGroup>
88
+
<!-- Old.Foo was removed after transformation -->
89
+
<MessageText="Old.Foo was removed after transformation" <!-- [!code highlight] -->
> If a expression includes item enumeration `%(itemType)`, item functions that returns a statistics of list would return result for each **distinct item**
> If a item does not represent a file, the most of intrinsic metadata would be empty.
203
+
204
+
205
+
106
206
## Expression Syntax
107
207
108
208
Expression syntax in msbuild has some flavor of Command Prompt and PowerShell.
@@ -115,7 +215,7 @@ Expression syntax in msbuild has some flavor of Command Prompt and PowerShell.
115
215
- access [registry item](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-properties?view=vs-2022#registry-properties) with its path
116
216
- **item accessor** `@(itemType)`
117
217
- use `@(itemType, '<sep>')` to concat items using separator
118
-
- use `@(itemType->'<metadata_expr>')` to collected transformed values to a list
218
+
- use `@(itemType->expr)` to collected transformed values generated by `expr` to a list, `expr` can be a string interpolation or [*item function*](https://learn.microsoft.com/en-us/visualstudio/msbuild/item-functions?view=vs-2022)
119
219
```xml
120
220
<ItemGroup>
121
221
<MyFileInclude="Programs.cs"/>
@@ -126,6 +226,8 @@ Expression syntax in msbuild has some flavor of Command Prompt and PowerShell.
Such approach seems to only allow updating on all existing items since `Include` could try to add new items and new metadata would result them to be duplicates.
301
+
302
+
```xml
303
+
<ItemGroup>
304
+
<FooListInclude="foo;bar;baz">
305
+
<FooMetaData>this is a foo metadata</FooMetaData>
306
+
</FooList>
307
+
</ItemGroup>
308
+
309
+
<TargetName="Hello">
310
+
<ItemGroup>
311
+
<FooList> <!-- no Include here --><!-- [!code highlight] -->
312
+
<!-- update all existing items from FooList -->
313
+
<FooMetaData>this is a bar metadata now!</FooMetaData> <!-- [!code highlight] -->
0 commit comments