views:

25

answers:

1

I would like to create a custom task that is called in a fashion such as this:

 <Target Name="Remap">
     <ItemGroup>
         <Entry Key="key1" Value="value1" />
         <Entry Key="key2" Value="value2" />
     </ItemGroup>

     <CustomTask 
         Entries="@(Entry)"
     />
 </Target>

Or this:

 <Target Name="Remap">
     <ItemGroup>
         <Entry>
             <Key>key1</Key>
             <Value>value1</Value>
         </Entry>
         <Entry>
             <Key>key2</Key>
             <Value>value2</Value>
         </Entry>
     </ItemGroup>

     <CustomTask 
         Entries="@(Entry)"
     />
 </Target>

I tried just using:

public class CustomTask : Task
{
    public override bool Execute()
    {
        ...
    }

    [Required]
    public ITaskItem[] Entries { get; set; }
}

But in the first case, I get the error:

error MSB4066: The attribute "Key" in element <Entry> is unrecognized.

And in the second case, while there is no error, the Entries collection is just empty.

Is there a way to accomplish this with MsBuild custom tasks?

A: 

Items in an itemgroup must have an Include= attribute that identifies it, so try something like:

<Target Name="Remap">
     <ItemGroup>
         <Entry Include="key1">
             <Value>value1</Value>
         </Entry>
         <Entry Include="key2">
             <Value>value2</Value>
         </Entry>
     </ItemGroup>

     <CustomTask 
         Entries="@(Entry)"
     />
 </Target>

The Value parts should appear as metadata in the items.

Jay Bazuzi