MSBuild 已知的項目中繼資料MSBuild well-known item metadata

下表說明在建立期間指派給每個項目的中繼資料。The following table describes the metadata assigned to every item upon creation. 每個範例都使用了下列項目宣告,以在專案中包含 C:\MyProject\Source\Program.cs 檔案。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)%(FullPath) 包含項目的完整路徑。Contains the full path of the item. 例如:For example:

C:\MyProject\Source\Program.csC:\MyProject\Source\Program.cs
%(RootDir)%(RootDir) 包含項目的根目錄。Contains the root directory of the item. 例如:For example:

C:\C:\
%(Filename)%(Filename) 包含項目的檔案名稱 (不含副檔名)。Contains the file name of the item, without the extension. 例如:For example:

ProgramProgram
%(Extension)%(Extension) 包含項目的副檔名。Contains the file name extension of the item. 例如:For example:

.cs.cs
%(RelativeDir)%(RelativeDir) 包含 Include 屬性中指定的路徑,直到最後一個反斜線 (\) 為止。Contains the path specified in the Include attribute, up to the final backslash (\). 例如:For example:

Source\Source\
%(Directory)%(Directory) 包含項目的目錄 (不含根目錄)。Contains the directory of the item, without the root directory. 例如:For example:

MyProject\Source\MyProject\Source\
%(RecursiveDir)%(RecursiveDir) 如果 Include 屬性包含萬用字元 **,此中繼資料會指定取代萬用字元的部分路徑。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.

如果資料夾 C:\MySolution\MyProject\Source\ 包含 Program.cs 檔案,而且專案檔包含此項目: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>

%(MyItem.RecursiveDir) 的值會是 MySolution\MyProject\Source\then the value of %(MyItem.RecursiveDir) would be MySolution\MyProject\Source\.
%(Identity)%(Identity) Include 屬性中指定的項目。The item specified in the Include attribute.. 例如:For example:

Source\Program.csSource\Program.cs
%(ModifiedTime)%(ModifiedTime) 包含上次修改項目時間的時間戳記。Contains the timestamp from the last time the item was modified. 例如:For example:

2004-07-01 00:21:31.5073316
%(CreatedTime)%(CreatedTime) 包含項目建立時間的時間戳記。Contains the timestamp from when the item was created. 例如:For example:

2004-06-25 09:26:45.8237425
%(AccessedTime)%(AccessedTime) 包含上次存取項目時間的時間戳記。Contains the timestamp from the last time the item was accessed.

2004-08-14 16:52:36.3168743

另請參閱See also