【问题标题】:Msbuild ItemGroup exclude doesn't work with wildcardsMsbuild ItemGroup exclude 不适用于通配符
【发布时间】:2018-02-08 10:29:00
【问题描述】:

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

【问题讨论】:

  • 您可以在这里使用答案:stackoverflow.com/questions/35498608/… 并调整正则表达式,使其排除任何匹配 \References\ 左右的内容。否则,您可能必须列出所有要排除的文件,即 然后根据该列表过滤 BinaryFiles 组。
  • 您使用的是哪个版本的 msbuild?
  • Microsoft (R) Build Engine 版本 15.1.1012.6693
  • 静态评估和目标处理之间的区别 - 排除模式在静态评估(“全局”项目组)期间有效,但在目标中无效
  • 打开了一个 GH 问题:github.com/Microsoft/msbuild/issues/2491

标签: .net msbuild csproj targets proj


【解决方案1】:

我可以排除 References 文件夹的唯一方法是使用正则表达式。这似乎有点老套,欢迎提出任何其他建议。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 2019-03-09
    • 2011-10-07
    相关资源
    最近更新 更多