2017-08-30 67 views
1

工作這的ItemGroup ItemsFromAnotherTarget包含:MSBUILD的ItemGroup排除不使用通配符

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

的想法是生成包含

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

所以我有另一個項目組BinaryFiles如下:

<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

你可以在這裏使用了答案:https://stackoverflow.com/questions/35498608/msbuild-how-can-i-exclude-wildcard-paths-matching-a-regex和調整正則表達式,因此包含任何與\ References \左右匹配的東西。否則,您可能必須列出要排除的所有文件,即,然後根據該列表過濾BinaryFiles組。 – stijn

+0

您使用的是哪個版本的msbuild? –

+0

Microsoft(R)Build Engine 15.1.1012.6693版本 – dushyantp

回答

2

我可以排除References文件夾的唯一方法是通過Regex。這看起來有些不禮貌,其他任何建議都是值得歡迎的。

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