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=http://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 (18)

  1. a) 0

    I don’t see any ‘x’ in the XML 😛

  2. Mike Fourie says:

    Hahahahaha 🙂 Ok, I suppose that’s technically correct. That’s what I get for cleaning up Dan’s original challenge.

    Let me rephrase: How many lines of output does the following MSBuild XML produce?

    Neil

  3. fcarlier says:

    It will try to match every element in Foo in Bar, and if they are equal, print out the name of the element.

    Since there are three elements identique elements in Foo and Bar, it will print out:

    a

    b

    c

    or so I guess

  4. Mike Fourie says:

    That’s definitely a reasonable guess, but not what the output winds up being (I’ll explain why later 🙂 Anyone else?

    Neil

  5. I still guess 0, because Foo and Bar are never identical regardless their includes.

  6. <a href=’http://www.yahoo.com‘></a> http://www.insurance-top.com/auto/”>http://www.insurance-top.com/auto/ <a href=’http://www.insurance-top.com‘>auto insurance</a>. <a href="http://www.insurance-top.com ">Insurance car</a>: auto insurance, insurance car, Best Insurance Web site
    . [url]http://www.insurance-top.com/car/[/url] [link=http://www.insurance-top.com]insurance quote[/link] from site .

  7. http://www.insurance-top.com/company/”>http://www.insurance-top.com/company/ auto site insurance. [URL=http://www.insurance-top.com]home insurance[/URL]: auto insurance, insurance car, Best Insurance Web site
    . [url=http://www.insurance-top.com]cars insurance[/url] from website .

  8. http://www.insurance-top.com/company/ auto site insurance. auto insurance, insurance car, Best Insurance Web site
    . from website .

Skip to main content