Msbuild ItemGroup exclude doesn't work with wildcards

天大地大妈咪最大 提交于 2019-12-24 00:07:04

问题


This Itemgroup ItemsFromAnotherTarget contains:

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

The idea is to generate another item group BinaryFiles containing

bin\GeneratedAssembly1.dll
bin\GeneratedAssembly2.dll
somefolder\somefile.exe
bin\anexe.exe

So I have the following:

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

So this generates the required item group. But if we replace the Exclude with a wild card, it doesn't work.

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

The issue is the References folder might have multiple folders and dlls, we need to exclude the whole References folder. Any idea how to do the filtering using a wild card?


回答1:


The only way I could get to exclude References folder is by Regex. It seems sort of hacky and any other suggestion is welcome.

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


来源:https://stackoverflow.com/questions/45964967/msbuild-itemgroup-exclude-doesnt-work-with-wildcards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!