Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MsBuild condition count items

Tags:

msbuild

I want error to be thrown if number of data-items more than one. Why doesn't the following work? How do I code correct expression?

<ItemGroup>
  <Data Include="a"/>
  <Data Include="b"/>
</ItemGroup>

<Error Text="Error!" Condition="@(Data->Count()) &gt; 1" />

ps. msbuild v4.0

like image 399
pamidur Avatar asked Sep 27 '13 10:09

pamidur


People also ask

What are MSBuild items and item types?

MSBuild items are inputs into the build system, and they typically represent files (the files are specified in the Include attribute). Items are grouped into item types based on their element names. Item types are named lists of items that can be used as parameters for tasks. The tasks use the item values to perform the steps of the build process.

Are inside and outside targets supported in MSBuild 15?

Both inside and outside targets are supported starting in MSBuild 15.0. The following example removes every .config file from the Compile item type. If an item is generated within a target, the item element can contain the KeepMetadata attribute.

When are the attributes in this section valid in itemgroup?

The attributes in this section are valid when they are specified for an item in an ItemGroup that's in a Target. The Remove attribute removes specific items (files) from the item type. This attribute was introduced in the .NET Framework 3.5 (inside targets only). Both inside and outside targets are supported starting in MSBuild 15.0.

What is the difference between return and exist in MSBuild?

Returns items that have the given metadata name and value. The comparison is case insensitive. Exists can also be used in other contexts; in MSBuild conditions, for example Condition="Exists ('path')"; or in Static property functions, for example $ ( [System.IO.File]::Exists ("path")).


1 Answers

I've found solution: You want to wrap your expression with the single quotes

<Error Text="Error!" Condition="'@(Data->Count())' &gt; 1" />
like image 138
pamidur Avatar answered Sep 30 '22 18:09

pamidur