我实际上有两个问题:
如何通过扩展名过滤文件列表(在ItemGroup中)?
我有两个通过XMLPeek从XML文件中读出的文件列表,我希望根据条件将它们合并在一起。可以在MSBuild中完成吗?
目前,我有这样的事情:
<Target Name="GetExportFileList">
<!-- Can't use XPath to filter the value by extension because MSBuild doesn't support XPath 2.0's ends-with() function -->
<XmlPeek XmlInputPath="$(XmlFile)"
Query = "//File[not(./@value = '') and not(./@value = preceding::File/@value)]/@value">
<!-- this file list will have files with two different extensions, we'll call them .ext1 and ext2 files - need a way to split this into two ItemGroups each containing only one of the file types -->
<Output TaskParameter="Result"
ItemName="ReferencedFiles" />
</XmlPeek>
<!-- .ext2 files are XML and contain references to other .ext1 files -->
<XmlPeek XmlInputPath="$(DirectlyReferencedExt2Files)"
Query="//Ext1[not(./@FilePath = '')]/@FilePath">
<Output TaskParameter="Result"
ItemName="IndirectlyReferencedExt1Files" />
</XmlPeek>
<!-- combine the two lists -->
<ItemGroup>
<AllExt1Files Include="@IndirectlyReferencedExt1Files" />
<AllExt1Files Include="@DirectlyReferencedExt1Files" Exclude="@AllExt1Files" />
</ItemGroup>
</Target>
所以回顾一下:
可能有一些非常简单的方法可以做到这一点,但是我无法了解MSBuild的工作原理以及在哪里找到我正在尝试做的参考(MSDN更令人困惑而不是有帮助:))
谢谢!
答案 0 :(得分:0)
这是所有标准的msbuild功能:
<ItemGroup>
<ReferencedFiles Include="a.ext1;b.ext1;c.ext2;d.ext2"/>
</ItemGroup>
<Target Name="FilterIt">
<ItemGroup>
<DirectlyReferencedExt1Files Include="%(ReferencedFiles.Identity)" Condition="'%(Extension)'=='.ext1'" />
<DirectlyReferencedExt2Files Include="%(ReferencedFiles.Identity)" Condition="'%(Extension)'=='.ext2'" />
<AllOfThem Include="@(DirectlyReferencedExt1Files);@(DirectlyReferencedExt2Files)" />
</ItemGroup>
<Message Text="@(DirectlyReferencedExt1Files)" />
<Message Text="@(DirectlyReferencedExt2Files)" />
<Message Text="@(AllOfThem)" />
</Target>
注意:您的问题是重复的,但是因为您问其中两个,很难找到完全重复项,因为SO要求。例如,请参阅How do you filter an ItemGroup?和{{ 3}}和MSBuild ItemGroup with condition