Skip to content
This repository was archived by the owner on Sep 17, 2020. It is now read-only.
This repository was archived by the owner on Sep 17, 2020. It is now read-only.

For Type="Class", add reflection based property/ParameterGroup discovery support #33

@binki

Description

@binki

It would be very useful for me if I could declare a Task using the Class syntax and let the parameters be automatically discovered just as if my Task was declared in an assembly. I think that if I wrote my Task as an assembly, MSBuild would use reflection over the properties of my class to discover which properties are supported. This means that if I am overriding an existing Task to intercept/extend it, I would automatically inherit the properties it uses and can augment them with additional properties.

However, for CodeTaskFactory and RoslynCodeTaskFactory, currently the parameters must be explicitly provided via <ParameterGroup/>. This makes sense and is even required for Type="Fragment" and Type="Method". However, this is quite limiting for my use case of Type="Class".

My idea for the design of this would be to add a new parameter to the <Code/> element to enable this capability. Another option is to simply automatically do parameter discovery when <ParameterGroup/> is absent and Type="Class". Two hypothetical examples of these options:

Explicit AutomaticParameters="True":

<UsingTask
  TaskName="Csc"
  TaskFactory="CodeTaskFactory"
  AssemblyFile="$(RoslynCodeTaskFactory)"
  Condition=" '$(RoslynCodeTaskFactory)' != '' ">
  <Task>
    <Reference Include="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" />
    <Code Type="Class" Language="cs" AutomaticParameters="True">
      <![CDATA[
        public class Csc : Microsoft.CodeAnalysis.BuildTasks.Csc
        {
          public override bool Execute()
          {
            // Do something interceptive here…

            return base.Execute();
          }
        }
      ]]>
    </Code>
  </Task>
</UsingTask>

Implicit omission of <ParameterGroup/>:

<UsingTask
  TaskName="Csc"
  TaskFactory="CodeTaskFactory"
  AssemblyFile="$(RoslynCodeTaskFactory)"
  Condition=" '$(RoslynCodeTaskFactory)' != '' ">
  <Task>
    <Reference Include="$(RoslynTargetsPath)\Microsoft.Build.Tasks.CodeAnalysis.dll" />
    <Code Type="Class" Language="cs">
      <![CDATA[
        public class Csc : Microsoft.CodeAnalysis.BuildTasks.Csc
        {
          public override bool Execute()
          {
            // Do something interceptive here…

            return base.Execute();
          }
        }
      ]]>
    </Code>
  </Task>
</UsingTask>

I’m planning to try to implement this. Please let me know if you have any suggestions and if this functionality would be accepted into RoslynCodeTaskFactory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions