Share via


A Little Batching Brainteaser

Every so often as we work through converting the Visual Studio builds over to MSBuild we stumble across a little quirk or entertaining bit of MSBuild XML that makes the team scratch its head. Dan sent this one around to the team a couple of weeks ago, and it's related to our previous post about unqualified metadata.

How many x's does the following MSBuild XML produce?

<

Project DefaultTargets="Build" xmlns=https://schemas.microsoft.com/developer/msbuild/2003>
<ItemGroup>
<Foo Include="a"/>
<Foo Include="b"/>
<Foo Include="c"/>
<Bar Include="a"/>
<Bar Include="b"/>
<Bar Include="c"/>
</ItemGroup>
<Target Name="Build">
<Message Text="@(Foo) @(Bar)" Condition="'%(Foo.Identity)'=='%(Bar.Identity)'"/>
</Target>
</Project>

To make it easier we'll make the question multiple choice. Is the answer:

a) 0
b) 2
c) 3
d) 9

No cheating! You can't run this through MSBuild to find out. Take a guess first, then try it out.

[ Author: Neil Enns]

Comments