Select Files containing a certain substring in MSBuild
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>
精彩评论