开发者

Override a duplicate Task in NAnt?

For better or worse, I've built my own msbuild task. I've given it the name 'ms开发者_JS百科build' and it's colliding with one from NAntContrib.

Assuming, I can't remove the one from NAntContrib, is there a way to override the contrib version while keeping the same task name?

Or perhaps another task could be written that can alias an already loaded task to be named something else?

Or I can probably change my task name.

Any info would be appreciated.


I have not seen a way you can overload task names. It sounds like the easiest thing to do would be to change the name of your tasks to something that is not msbuild.


A bit of a hack I found that seem to work is basically giving your task a namespace prefix.

[TaskName("zz:msbuild")]
public class MsbuildTask : ExternalProgramBase
{
}

Then in your nant build file:

<project default="Build" name="TestBuild"
    xmlns="http://nant.sf.net/schemas/nant-0.85.win32.net-1.0.xsd"
    xmlns:zz="http://nant.sf.net/schemas/nant-0.85.win32.net-1.0.xsd">
    <target name="Build">
        <zz:msbuild target="Build" project="TestBuild.sln"
            verbosity="${msbuild.verbosity}">
            <property name="Configuration" value="${build.configuration}" />
        </zz:msbuild>
    </target>
</project>

The only thing I don't like is the fact that I have to embed the prefix in the TaskNameAttribute. This is necessary because internally NAnt uses the string "zz:msbuild" to hash the task and looks up based on XmlNode.Name property.

Also notice that the prefix is pointing to the default namespace. This is because NAnt discards nodes with namespaces other than the default NAnt namespace. I can kind of understand why they did that but I don't know that it's absolutely necessary.

Looking at the NAnt source, it seems very much feasible to make the adjustments so that I don't have to embed the prefix and to give the task a different namespace.

The alternative to this approach, the one that I've been using previously, was to use task name like "zz.msbuild". But that didn't really seem correct. I remember reading somewhere having a period in element names is not recommended. But more than that, it didn't look good :P

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜