Framework.Metadata is redundant

Jun 21, 2013 at 10:27 PM
I did a brief search and didn't see anything about this, but ignore if it's already known.

You can already add metadata to an Item/Collection of items with msbuild syntax
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="test">
  <ItemGroup>
    <Foo Include="A;B;C;D"/>
  </ItemGroup>
  <!-- 4 Foo exist. A, B, C, and D -->
  
  <ItemGroup>
    <Foo Condition=" '%(Identity)' == 'B' ">
      <Bar>baz</Bar>
    </Foo>
  </ItemGroup>
  <!-- now only Foo B has metadata Bar=baz.  This metadata does not exist for all other Foos -->
  <ItemGroup>
    <Foo>
      <Flub>jelly</Flub>
    </Foo>
  </ItemGroup>
  <!-- now all Foos have metadata Flub=jelly -->
  
  <ItemGroup>
    <Foo>
      <Flub2>%(Fullpath)</Flub2>
    </Foo>
  </ItemGroup>
  <!-- we can even reference other metadata, although this can have slightly strange behavior depending on msbuild 3.5 or 4.0 -->
  
  <ItemGroup>
    <Foo2 Include="@(Foo)" Condition=" '%(Identity)' == 'C' ">
      <Baz>bonk</Baz>
    </Foo2>
  </ItemGroup>
  <!-- 1 Foo2 exists.  It inherited all metadata from Foo C, as well as gained additional metadata. So Foo2 C has %(Flub) %(Flub2) %(Baz) -->
  
  <Message Text="@(Foo -> 'Foo ID: %(Identity) Bar: %(Bar) Flub: %(Flub) Flub2: %(Flub2)', '%0a')"/>
  <Message Text="@(Foo2 -> 'Foo2 ID: %(Identity) Bar: %(Bar) Flub: %(Flub) Flub2: %(Flub2) Baz:%(Baz)', '%0a')"/>
</Target>
</Project>
output using msbuild 3.5
Project "c:\boo\msbuildtest\test.proj" on node 0 (default targets).
Project file contains ToolsVersion="4.0", which is not supported by this version of MSBuild. Treating the project as if
 it had ToolsVersion="3.5".
test:
  Foo ID: A Bar:  Flub: jelly Flub2: c:\boo\msbuildtest\D
  Foo ID: B Bar: baz Flub: jelly Flub2: c:\boo\msbuildtest\B
  Foo ID: C Bar:  Flub: jelly Flub2: c:\boo\msbuildtest\D
  Foo ID: D Bar:  Flub: jelly Flub2: c:\boo\msbuildtest\D
  Foo2 ID: C Bar:  Flub: jelly Flub2: c:\boo\msbuildtest\D Baz:bonk
Done Building Project "c:\boo\msbuildtest\test.proj" (default targets).
output with 4.0 (note I installed VS2012 so behavior may be slightly different than without 2012)
Project "C:\boo\msbuildtest\test.proj" on node 1 (default targets).
test:
  Foo ID: A Bar:  Flub: jelly Flub2: C:\boo\msbuildtest\A
  Foo ID: B Bar: baz Flub: jelly Flub2: C:\boo\msbuildtest\B
  Foo ID: C Bar:  Flub: jelly Flub2: C:\boo\msbuildtest\C
  Foo ID: D Bar:  Flub: jelly Flub2: C:\boo\msbuildtest\D
  Foo2 ID: C Bar:  Flub: jelly Flub2: C:\boo\msbuildtest\C Baz:bonk
Done Building Project "C:\boo\msbuildtest\test.proj" (default targets).
Coordinator
Jun 28, 2013 at 8:43 AM
Hi

Thanks for the detailed info. I see this task was added in 2009 when perhaps this functionality wasn't possible, I'd have to check. We could mark it for deprecation, but we would break users who may have implemented it if we removed it. For now I'm happy to let it stay in the pack, but I will update the documentation on the next release to include your guidance.

Mike
Coordinator
Jun 28, 2013 at 8:45 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Marked as answer by mikeFourie on 10/9/2013 at 3:16 PM