msbuild: How can I exclude wildcard paths matching a regex?

纵然是瞬间 提交于 2019-12-13 19:09:05

问题


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>

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


回答1:


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>


来源:https://stackoverflow.com/questions/35498608/msbuild-how-can-i-exclude-wildcard-paths-matching-a-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!