Msbuild ItemGroup exclude不适用于通配符 [英] Msbuild ItemGroup exclude doesn't work with wildcards
问题描述
此项目组ItemsFromAnotherTarget
包含:
..\..\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
的项目组
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
文件夹.知道如何使用通配符进行过滤吗?
我唯一可以排除References
文件夹的方法是Regex.似乎有点不客气,欢迎任何其他建议.
<ItemGroup>
<BinaryFiles Include="@(ItemsFromAnotherTarget)" Condition="(!$([System.Text.RegularExpressions.Regex]::IsMatch('%(Identity)', `.\\References\\.`))) and ('%(Extension)'=='.dll' or '%(Extension)'=='.exe')" />
</ItemGroup>
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>
这篇关于Msbuild ItemGroup exclude不适用于通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!