Msbuild ItemGroup 排除不适用于通配符

问题描述 投票:0回答:2

此项目组

ItemsFromAnotherTarget
包含:

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

这个想法是生成另一个项目组

BinaryFiles
包含

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
文件夹。知道如何使用通配符进行过滤吗?

.net msbuild csproj targets proj
2个回答
6
投票

我可以排除

References
文件夹的唯一方法是通过正则表达式。这看起来有点老套,欢迎任何其他建议。

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

0
投票

这已经很老了,但是更好的解决方法是这样的:

<ItemGroup>
    <FilesToExclude Include="..\..\**\References\**;..\..\References\**\*.dll;...." />
    <BinaryFiles Include="@(ItemsFromAnotherTarget)" Exclude="@(FilesToExclude)" />
</ItemGroup>
© www.soinside.com 2019 - 2024. All rights reserved.