tags:

views:

53

answers:

2

Given this Itemgroup:

<ItemGroup>
  <Foo Include="First">
    <Value>1</Value>
  </Foo>
  <Foo Include="Second">
    <Value>2</Value>
  </Foo>
</ItemGroup>

How can I get the Value metadata for the second item (2)? I'm thinking along the lines of:

<Message Text="%(Foo.Value)" Condition="'' == 'Second'" />

But I don't know how to write the Condition attribute.

Thanks!

A: 

I am not a pro with msbuild but I doubt this is possible. I found a workaround, you can add another metadata tag inside your Foo group and this will work as described below.

<ItemGroup>
    <Foo Include="First">
        <Value>1</Value>
        <Source>First</Source>
    </Foo>
    <Foo Include="Second">
        <Value>2</Value>
        <Source>Second</Source>
    </Foo>
    <Foo Include="Third">
        <Value>2</Value>
    </Foo>
</ItemGroup>

and the conditional like this will print only for the 2nd of the above 3 elements

<Message Text="%(Foo.Value)" Condition="'%(Foo.Source)' == 'Second'"  />
Marcel Gosselin
+5  A: 

Identity metadata gives the item's value.

<Message Text="%(Foo.Value)" Condition="'%(Foo.Identity)' == 'Second'" />
Ankit
Thanks I just learned something.
Marcel Gosselin
Me too, thanks!
michielvoo
how would i get this value ("2") into a string variable without using Message?