Поделиться через


MSBuild well-known item metadata

Item metadata are values attached to items. Some are assigned by MSBuild to items when items are created, but you can also define any metadata you need. Some user-defined metadata values have meaning to MSBuild, specific tasks, or SDKs such as the .NET SDK.

The first table in this article describes the metadata assigned to every item upon creation. The next table shows some optional metadata that has meaning for MSBuild, which you can define to control build behavior. In each example, the following item declaration was used to include the file C:\MyProject\Source\Program.cs in the project.

<ItemGroup>
    <MyItem Include="Source\Program.cs" />
</ItemGroup>
Item metadata Description
%(FullPath) Contains the full path of the item. For example:

C:\MyProject\Source\Program.cs
%(RootDir) Contains the root directory of the item. For example:

C:\
%(Filename) Contains the file name of the item, without the extension. For example:

Program
%(Extension) Contains the file name extension of the item. For example:

.cs
%(RelativeDir) Contains the path specified in the Include attribute, up to the final backslash (\). For example:

Source\

If the Include attribute is a full path, %(RelativeDir) begins with the root directory %(RootDir). For example:

C:\MyProject\Source\
%(Directory) Contains the directory of the item, without the root directory. For example:

MyProject\Source\
%(RecursiveDir) If the Include attribute contains the wildcard **, this metadata specifies the part of the path that replaces the wildcard. For more information on wildcards, see How to: Select the files to build.

If the folder C:\MySolution\MyProject\Source\ contains the file Program.cs, and if the project file contains this item:

<ItemGroup>

<MyItem Include="C:\**\Program.cs" />

</ItemGroup>

then the value of %(MyItem.RecursiveDir) would be MySolution\MyProject\Source\.
%(Identity) The item specified in the Include attribute. For example:

Source\Program.cs
%(ModifiedTime) Contains the timestamp from the last time the item was modified. For example:

2004-07-01 00:21:31.5073316
%(CreatedTime) Contains the timestamp from when the item was created. For example:

2004-06-25 09:26:45.8237425
%(AccessedTime) Contains the timestamp from the last time the item was accessed.

2004-08-14 16:52:36.3168743

See also