2

I've done a couple of custom 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)?

1 Answer 1

3

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is definitely a way to go which I have allready considered as mentioned in the post. I'll probably end up doing it that way, but would like to have a more reader friendly way of doing it. Will post back if I find a good alternative.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.