msbuildconditional-statements

How do I do a MSBuild Condition testing if an ItemGroup contains an item?


This should be simple, but I can't find how to do this (or maybe it's not possible).

In MSBuild I have an ItemGroup that is a list of files. I want to execute a task only if a particular file is in that ItemGroup

Something like:

<Copy Condition="@(Files) <contains> C:\MyFile.txt" .... />

Any way to do this? Preferably without writing a custom task.

Edit: The list of files is only to do with the condition. Otherwise it has no relation to the task.


Solution

  • Try

    <Copy Condition="'%(Files.Identity)' == 'C:\MyFile.txt'" .. />