I want to pass a semi-colon separated list of strings.
Each string represents a file name.
<PropertyGroup>
<FileNames>Newtonsoft.Json;Reactive</FileNames>
<PathToOutput>C:/</PathToOutput>
</PropertyGroup>
Now I want to create an item group which should give me all the files in particular folder excluding list of Filename, something like:
<ItemGroup>
<ReleaseFiles Include="$(PathToOutput)\**\*.*" Exclude="%(identity)-> identity.contains(%FileNames)"/>
</ItemGroup>
How do I iterate through current folder's files and match each ones name if it contains any one filename in Filenames variable.
Pretty sure this is a duplicate but I cannot find it at the moment so here it goes:
Include=$(Property)
Exclude
only works if you have a list of exact matches, but you need more arbitrary filtering here so you'll need Condition
Contains
is a property function (well, or a System::String method) so won't work as such on metadata, hence we turn metadata into a string firstIn code:
<PropertyGroup>
<FileNames>Newtonsoft.Json;Reactive</FileNames>
<PathToOutput>C:/</PathToOutput>
</PropertyGroup>
<Target Name="FilterBasedCommaSeperatedProperty">
<ItemGroup>
<!-- property -> item -->
<Excl Include="$(FileNames)"/>
<!-- list all and add metadata list -->
<AllReleaseFiles Include="$(PathToOutput)\**\*.*">
<Excl>%(Excl.Identity)</Excl>
</AllReleaseFiles >
<!-- filter to get list of files we don't want -->
<FilesToExclude Include="@(AllReleaseFiles)"
Condition="$([System.String]::Copy('%(FileName)').Contains('%(Excl)'))"/>
<!-- all but the ones to exclude -->
<ReleaseFiles Include="@(AllReleaseFiles)" Exclude="@(FilesToExclude)"/>
</ItemGroup>
<Message Text="%(ReleaseFiles.Identity)" />
</Target>