开发者

MSBuild: Writing and calling a Custom Task, but MSBuild thinks I need a TaskFactory

I'm getting into MSBuild to handle various targets of projects and I'm finding it to be quite flexible. (It's also helping me understand the possibilities of our CI system, too)

I need to get the current SVN revision of the project, for which I have written a custom task that calls SubWCRev and parses the output.

I reference this using the element:

<UsingTask TaskName="xxx.Elements.Build.MSBuildTasks.SubWCRev" AssemblyFile="D:\dev\xxx_presentation\Build\xxx.Elements.Build.dll">
    <ParameterGroup>
        <LastCommittedRevision ParameterType="System.Int" Required="False" Output="True" />
        <MixedRevisionRangeMinimum ParameterType="System.Int" Required="False" Output="True" />
        <MixedRevisionRangeMaximum ParameterType="System.Int" Required="False" Output="True" />
        <HasLocalModifications ParameterType="System.Boolean" Required="False" Output="True" />
    </ParameterGroup>
</UsingTask>

I then execute the task ...

  <Target Name="Version" BeforeTargets="BuildDatabase">
        <xxx.Elements.Build.MSBuildTasks.SubWCRev WorkingCopyDir="$(ProjectDir)..">
            <Output TaskParameter="LastCommittedRevision" ItemName="LastCommittedRevision" />
            <Output TaskParameter="MixedRevisionRangeMinimum" ItemName="MixedRevisionRangeMinimum" />
            <Output TaskParameter="MixedRevisionRangeMaximum" ItemName="MixedRevisionRangeMaximum" />
            <Output TaskParameter="HasLocalModifications" ItemName="HasLocalModifications" />
        </xxx.Elements.Build.MSBuildTasks.SubWCRev>
        <Message Text="Revision is @(LastCommittedRevision)" />
    </Target>

My problem is that MSBuild insists I use the TaskFactory attribute, which this document says is optional. And I'm also seeing that TaskFactory is particularly for Inline Tasks, which I am开发者_如何学JAVA not interested in.

The error message is:

The required attribute "TaskFactory" is empty or missing from the element UsingTask.

Where am I going wrong?

(And by the way, I'm finding MSBuild Sidekick 3 to be excellent and reducing the resistance of what can become a pretty complicated script.)


That attribute is optional when you are specifying UsingTask in the traditional manner to just point to a task in an assembly:

<UsingTask 
   TaskName="MyCustomTask"
   AssemblyFile="$(PathToTasks)/MyCustomTasks.dll"
   />

When specifying an inline task, the attribute is no longer optional. You then use:

<UsingTask
   TaskName="EnableAllPropertyFunctions"
   TaskFactory="CodeTaskFactory"
   AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
   <ParameterGroup>...
   <Task>...
</UsingTask>

What you are doing appears to mix both of those. If you are using a task from the built assembly "D:\dev\xxx_presentation\Build\xxx.Elements.Build.dll", then you shouldn't be specifying the ParameterGroup, MSBuild knows how to discover the parameters, and that it is present in your declaration implies that MSBuild should be trying to find the rest of the inline task.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜