【发布时间】:2012-08-26 17:10:09
【问题描述】:
如何根据特定条件(例如文件扩展名或项目的元数据)过滤现有的 ItemGroup?
在本例中,我将使用文件扩展名。我正在尝试过滤 VS 定义的“无”ItemGroup,以便我的目标可以对给定扩展名的所有文件进行操作。
例如,可以定义以下内容:
<ItemGroup>
<None Include="..\file1.ext" />
<None Include="..\file2.ext" />
<None Include="..\file.ext2" />
<None Include="..\file.ext3" />
<None Include="..\file.ext4" />
</ItemGroup>
我想过滤上面的“无”ItemGroup,使其仅包含ext 扩展名。请注意,我确实不想指定要排除的所有扩展,因为它们会因项目而异,而且我正在尝试使我的目标无需修改即可重复使用。
我尝试在目标中添加Condition:
<Target Name="Test">
<ItemGroup>
<Filtered
Include="@(None)"
Condition="'%(Extension)' == 'ext'"
/>
</ItemGroup>
<Message Text="None: '%(None.Identity)'"/>
<Message Text="Filtered: '%(Filtered.Identity)'"/>
</Target>
但遗憾的是,它不起作用。我得到以下输出:
Test:
None: '..\file1.ext'
None: '..\file2.ext'
None: '..\file.ext2'
None: '..\file.ext3'
None: '..\file.ext4'
Filtered: ''
【问题讨论】:
-
我相信 %(Extension) 需要是 '.ext'
-
-
我的意思是它实际上需要是'.ext',就像第一个字符用点一样,这样就可以了。