开发者

MSBuild custom Task with variable no of input parameters

I've done a couple of cust开发者_运维知识库om Tasks in MSBuild, but I am facing a new situation here.

In short, I want to do this:

<Target Name="MyTarget">
  <CustomTask Files="">
     <Input Name="SomeName" Action="SomeActionName />
     <Input Name="SomeName" Action="SomeActionName />
     <Input Name="SomeName" Action="SomeActionName />
  </CustomTask>
</Target>

I want to do this as I find it more readable than using Itemgroups/propertygroups. There is an attribute such as Output which is almost what I need. It should just be Input instead (hence the name).

So far I've attempted solving this issue using two tasks: CustomTask and InputTask.

Please note that Input does not have to be a Task. This was just a test and a means of getting a variable sized collection of inputs.

public class CustomTask : Task
{
    [Required]
    public TaskItem[] Files { get; set; }

    public InputTask[] Subs { get; set; }

    public override bool Execute()
    {
        if(Subs != null)
        {
            Subs.ToList().ForEach(sub => sub.Execute());
        }
        else
        {
            Log.LogMessage("No Subs");
        }
        return true;
    }
}

public class InputTask: Task
{
    [Required]
    public TaskItem Name{ get; set; }

    [Required]
    public TaskItem Action{ get; set; }

    public override bool Execute()
    {
        Log.LogMessage("" + Name + " should " + Action);
        return true;
    }
}

The idea was that MBSuild could "detect" the sub tasks and would then hand me a collection of them, but I just get an MSB4067 error.

I've have looked through a lot of the online OS tasks and the official documentation, but I haven't found any such example.

Is this even possible to do this way?

If not, how would you recommend I solve this (PropertyGroup/ItemGroup/Other)?


What you are trying to do is not possible. You can approximate it with item metadata.

<Target Name="MyTarget"> 

   <ItemGroup>
      <Input Identity="SomeName"><Action>SomeActionName</Action></Input>
      <Input Identity="SomeName"><Action>SomeActionName</Action></Input> 
      <Input Identity="SomeName"><Action>SomeActionName</Action></Input>
   </ItemGroup>

   <CustomTask Files="" Input="@(Input)"> 

</Target>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜