2017-08-30 61 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>