简体   繁体   中英

Msbuild ItemGroup exclude doesn't work with wildcards

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM