I have an ItemGroup
that contains some files (And I have no control on how this list is generated):
<ItemGroup>
<AllFiles Include="Assembly1.dll;Assembly1.Tests.dll"/>
<AllFiles Include="Assembly2.dll;Assembly2.Tests.dll"/>
...
</ItemGroup>
And I would like to create a second ItemGroup
(based on the first one) holding only for filenames matching ****.Tests.dll
. That is FilteredFiles
should be: Assembly1.Tests.dll
, Assembly2.Tests.dll
, ...
So far I tried:
<ItemGroup>
<FilteredFiles Include="@(AllFiles)" Condition="$([System.Text.RegularExpressions.Regex]::IsMatch(%(Filename), '\.Tests\.dll'))"/>
</ItemGroup>
But it doesn't seem to work.
PS: I would also like for non case sensitive matches but that's another issue.
You need to use item batching using the % instead of the @. This will work on the items one by one instead of including them all at the same time. You had the condition right, which I assume you found somewhere else.
<ItemGroup>
<FilteredFiles Include="%(AllFiles.Identity)" Condition="$([System.Text.RegularExpressions.Regex]::IsMatch(%(Filename), '\.Tests\.dll'))"/>
</ItemGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With