【发布时间】:2016-01-27 18:57:37
【问题描述】:
我其实有两个问题:
如何按扩展名过滤文件列表(在 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>
回顾一下:
- 我需要一种方法来将所有 .ext1 和 .ext2 类型的文件分别从 ReferencedFiles 提取到 DirectlyReferencedExt1Files 和 DirectlyReferencedExt2Files(因为我不能在 MSBuild 中使用 XPath 2.0 查询)
- 将 DirectlyReferencedExt1Files 和 IndirectlyReferencedExt1Files(从 DirectlyReferencedExt2Files 中提取)合并到一个列表中进行处理。
可能有一些非常简单的方法可以做到这一点,但我无法理解 MSBuild 的工作原理以及在哪里可以找到我正在尝试做的事情的参考(MSDN 比有用更令人困惑:))
谢谢!
【问题讨论】:
标签: merge msbuild filtering file-type