开发者

Select Files containing a certain substring in MSBuild

开发者 https://www.devze.com 2022-12-15 12:25 出处:网络
开发者_如何学GoSuppose 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
开发者_如何学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

精彩评论

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