Msbuild ItemGroup排除不适用于通配符

时间:2017-08-30 15:58:36

标签: .net msbuild csproj targets proj

此项目组ItemsFromAnotherTarget包含:

..\..\References\AnotherFolder\ReferencedAssembly.dll
bin\GeneratedAssembly1.dll
bin\GeneratedAssembly2.dll
somefolder\somefile.txt
somefolder\somefile.exe
bin\anexe.exe

我们的想法是生成另一个包含

的项目组BinaryFiles
bin\GeneratedAssembly1.dll
bin\GeneratedAssembly2.dll
somefolder\somefile.exe
bin\anexe.exe

所以我有以下内容:

<ItemGroup>
    <BinaryFiles Include="@(ItemsFromAnotherTarget)" Condition="'%(Extension)'=='.dll' or '%(Extension)'=='.exe'" Exclude="..\..\References\AnotherFolder\ReferencedAssembly.dll" />
</ItemGroup>

因此,这会生成所需的项目组。但是如果我们用外卡替换Exclude,它就不起作用。

Exclude="..\..\**\References\**"
Exclude="..\..\References\**\*.dll"
Exclude="..\..\References\**\*"
None of these work.

问题是References文件夹可能有多个文件夹和dll,我们需要排除整个References文件夹。知道如何使用外卡进行过滤吗?

1 个答案:

答案 0 :(得分:2)

我可以排除References文件夹的唯一方法是使用Regex。它看起来有点像hacky,欢迎任何其他建议。

<ItemGroup>
    <BinaryFiles Include="@(ItemsFromAnotherTarget)" Condition="(!$([System.Text.RegularExpressions.Regex]::IsMatch('%(Identity)', `.\\References\\.`))) and ('%(Extension)'=='.dll' or '%(Extension)'=='.exe')" />
</ItemGroup>
相关问题