开发者

Select Files containing a certain substring in MSBuild

开发者_如何学Go

Suppose I have a bunch of files in a folder:

foo.test.txt
bar.txt
...

And I want to create an ItemGroup to exclude files containing ".test." somewhere in the title, how would I do that in MSBuild?

<!-- Can't change this part -->
<Items Include="*.txt" />

<CreateItem Include="@(Items)" Condition="'%(Items.Exclude)'!='true' AND (???)">
  <Output TaskParameter="Include" ItemName="ItemsToProcess"/>
</CreateItem>

Where the ??? should be something like:

!Contains(%(Items), ".test.")

Except that I don't know how to do that in MSBuild.


How about using Exclude:

<CreateItem Include="@(Items)" Exclude="*test*" >
  <Output TaskParameter="Include" ItemName="ItemsToProcess"/>
</CreateItem>


KMoraz is off to a good start, but since MSBuild 3.5 you can just use the ItemGroup syntax even inside of targets. So that would be something like:

<Project ...>
    <ItemGroup>
        <Items Include="*" Exclude="*.text.*"/>
    </ItemGroup>
</Project>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜