msbuild:如何排除与正则表达式匹配的通配符路径? [英] msbuild: How can I exclude wildcard paths matching a regex?

查看:97
本文介绍了msbuild:如何排除与正则表达式匹配的通配符路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包含所有与*.c匹配的文件,包括子目录中的 ,对于其路径(在解决方案根目录下)包含一个或多个组件(目录名或文件名)的任何文件以下划线开头.

I want to include all files which match *.c, including in subdirectories, except for any file where its path (beneath the solution root) contains one or more components (directory name or filename) beginning with an underscore.

由于某种原因,这是行不通的:

For some reason, this isn't working:

 <ItemGroup>
    <ClCompile Condition="!$([System.Text.RegularExpressions.Regex]::IsMatch('%(Identity)', `.*[/\\]_.*`))" Include="../../src/foo/**/*.c"/>
</ItemGroup>

如何在msbuild中做到这一点?我正在使用msbuild 14.0.

How can I do this in msbuild? I'm using msbuild 14.0.

推荐答案

您使用的sytnax可以过滤现有的ItemGroup,但不能在创建一个时进行过滤(我无法立即找到该文档的记录位置);这意味着可以:

The sytnax you use is fine for filtering existing ItemGroups, but not while creating one (I don't immediately find where this is documented); which means this is ok:

<ItemGroup>
  <MatchingCFiles Include="../../src/foo/**/*.c"/>
  <ClCompile Condition="!$([System.Text.RegularExpressions.Regex]::IsMatch('%(Identity)', `.*[/\\]_.*`))" Include="@(MatchingCFiles)"/>
</ItemGroup>

这篇关于msbuild:如何排除与正则表达式匹配的通配符路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆