如何过滤 ItemGroup? [英] How do you filter an ItemGroup?
问题描述
我正在尝试从另一个创建过滤项目组,其中过滤后的项目组将仅包含第一个组中具有指定文件扩展名的项目.
I'm trying to create a filtered item group from another one, where the filtered item group will only contain items from the first group that have a specified file extension.
我收到以下错误:
错误 MSB4190:在此条件'%(Extension)'=='.sys'"中不允许对位置 1 的内置元数据Extension"的引用.
error MSB4190: The reference to the built-in metadata "Extension" at position 1 is not allowed in this condition "'%(Extension)'=='.sys'".
当我运行这个时:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="Go"
ToolsVersion="4.0">
<ItemGroup>
<Files Include="X.exe"/>
<Files Include="Y.sys"/>
</ItemGroup>
<ItemGroup>
<SysFiles Include="%(Files.Identity)" Condition="'%(Extension)'=='.sys'">
</SysFiles>
</ItemGroup>
<Target Name="Go">
<Message Text="SysFiles=@(SysFiles)"/>
</Target>
</Project>
首先,我不明白为什么这个位置不允许元数据?是msbuild的一些人为限制还是未实现的部分?
Firstly, I can't understand why the meta data isn't allowed at this position? Is it some artificial restriction or unimplemented part of msbuild?
其次,实现这种转换的简洁方法是什么?
Secondly, what's a concise way of achieving this kind of transform?
非常感谢.
推荐答案
好的,我发现如果我在目标 Go 中指定 ItemGroup SysFiles,它将正常工作.
Ok, I've found if I specify the ItemGroup SysFiles inside target Go, it will work without error.
这篇关于如何过滤 ItemGroup?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!