具有有关文件的自定义元数据的ItemGroup [英] ItemGroup With Custom Metadata regarding files
问题描述
我正在尝试创建一个名为"Files"的任务项组,其中包含名为"TargetPath"的元数据属性,其中填充了文件的相对路径.
I’m trying to create a "Files" task item group with a metadata attribute called "TargetPath" populated with the relative path to a file.
示例:
对于这些路径:
Example:
For these paths:
D:\ Test \ Blah.exe
D:\ Test \ Config \ fun.config
D:\ Test \ zh-CN \ my.resources.dll
D:\Test\Blah.exe
D:\Test\Config\fun.config
D:\Test\en-US\my.resources.dll
输出应为:
文件目标= Blah.exe
目标文件= Config \ fun.config
目标文件= en-US \ my.resources.dll
File Target = Blah.exe
File Target = Config\fun.config
File Target = en-US\my.resources.dll
这是我的最佳尝试...希望这可以使我的问题更清楚:
Here is my best attempt... hopefully this makes my question clearer:
<ItemGroup>
<Files Include="d:\test\**\*" >
<TargetPath>%(RecursiveDir)%(Filename)%(Extension)</TargetPath>
</Files>
</ItemGroup>
<Message Text="File Target = @(Files->'%(TargetPath)')"/>
我想正确地填充"TargetPath" ...目前看来它为null或为空.有人知道我想念什么吗?
I'd like "TargetPath" populated correctly... currently it appears to be null or empty. Anyone know what I'm missing?
是的,我知道我可以做到:
Yes, I realize I can do this:
<Message Text="File Target = @(Files->'%(RecursiveDir)%(Filename)%(Extension)')"/>
但是,我正在建立此ItemGroup以使用ResolveManifestFiles MSBuild任务,该任务要求我使用TargetPath元数据属性来构建TaskItem以便能够自定义该值.
However, I'm building up this ItemGroup to use the ResolveManifestFiles MSBuild task, which requires that I build up a TaskItem with the TargetPath metadata attribute to be able to customize that value.
推荐答案
您正在尝试在创建项目组之前将动态元数据分配给该项目组.在您的示例中,无需创建自定义元数据,因为此信息已经是众所周知的元数据的一部分,因此您可以执行以下操作:
You're trying to assign dynamic metadata to an itemgroup before it's created. In your example there's no need to create custom metadata since this information is already part of the well-known metadata, so you can just do:
<ItemGroup>
<Files Include="d:\test\**\*" ></Files>
</ItemGroup>
<Message Text="File Target = @(Files->'%(RecursiveDir)%(Filename)%(Extension)')"/>
或者:
<Message Text="File Target = %(Files.RecursiveDir)%(Files.Filename)%(Files.Extension)"/>
此示例使用 CreateItem 任务来动态更新项目组:
This example uses CreateItem task to dynamically update the itemgroup:
<ItemGroup>
<Files Include="d:\test\**\*" ></Files>
</ItemGroup>
<CreateItem
Include="@(Files)"
AdditionalMetadata="TargetPath=%(RecursiveDir)%(Filename)%(Extension)">
<Output TaskParameter="Include" ItemName="Files"/>
</CreateItem>
这篇关于具有有关文件的自定义元数据的ItemGroup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!