Hello,

There are two "issues" I've run into with NAnt recently.

  The first of these is that when I wrote the VS.NET addin, I ended up
writing TaskNode classes that wrap each Task. This caused me to run into a
host of problems because there isn't enough metadata on a Task to state what
attributes are required under what conditions and how to access child XML
elements of a task (other than ones that represent a fileset) in a standard
way. When I first contributed the Addin, many of you remarked on how it
would be nicer if we had more metadata so that each time a new drop of NAnt
comes out or a new task is available, the addin is updated to show the
correct property editors etc.

  The second of these is that when I wrote the MSI task (in NAntContrib),
the amount of error cases became horrendous. I had several XML elements that
are nested and should have unique "name" attributes, and other XML elements
that refer to those previously defined names.

----

To make a long story short, I've added a .NET attribute "SchemaValidator"
that when applied to a Task class forces it to validate itself against an
XML Schema prior to being executed in an NAnt target.

To use this, you need to do the following:

    -Create a Task that inherits from
NAnt.Contrib.Tasks.SchemaValidatedTask.
    -Write an XML Schema for the Task. Make the targetNamespace the same as
the name of the Task's class.
    -Place the XML Schema (.xsd) in the same directory as your Task's
source.
    -Add a xsd target to the NAntContrib compile.schemas target to compile
your schema. This gets precompiled
      into NAnt.Contrib.Schemas.dll, which gets deleted after the Tasks are
built. (The compiled schemas get stored
      in the Task's assembly).
    -Add a using statement to the task you created in the first step to
declare the compiled schema's C# namespace
    -Add a [TaskValidator(type)] attribute that takes the Type of the root
element of your task as generated by xsd.
    -In InitializeTask(), call base.InitializeTask(TaskNode) and then
retrieve the SchemaObject property. This will
      return the class xsd generated for the root element of your task's
schema populated with values from the currently
      running task.

What does this buy you?

    -Error messages with the line number that describe invalid elements,
attributes, or relationships in a task
    -Ability to make sure XML matches criteria prior to execution (reduce
error handling code)
    -Ability to get a C# object model that wraps your task's data instead of
using XmlElement.SelectSingleNode.
    -Ability to validate an entire NAnt project prior to executing the first
task in the future, if we had a schema for NAnt.
    -Ability to use the System.Xml.Schema API to create instances of the
Task from the Addin (future).

Try it out and let me know what you think,
-Jayme



-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
_______________________________________________
Nant-developers mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-developers

Reply via email to