Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 481
Ray Avatar asked Sep 29 '11 08:09

Ray


People also ask

What is ItemGroup in MSBuild?

In addition to the generic Item element, ItemGroup allows child elements that represent types of items, such as Reference , ProjectReference , Compile , and others as listed at Common MSBuild project items.

What is ItemGroup?

An item group is a collection of products which share similar attributes like color, production, features, or usage. Item groups can also be formed based on the markets in which they're sold or if they're similar in price.


1 Answers

Try

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

like image 143
radical Avatar answered Oct 05 '22 19:10

radical