nantfilesetnantcontrib

How to detect whether fileset is defined?


My custom NAnt task relies on a certain fileset. It is considered to be defined by the time the task executes. I'd like to make sure fileset was defined before using it. I'm thinking of something similar to property::exists('property').

I failed to find the appropriate function. Is it possible with NAnt (or NAntContrib) out of the box?


Solution

  • Generally, tasks should not depend on filesets or properties. Instead, they should take explicit parameters. An existing fileset can be reused using refid, so there's no redeclaration resulting from this. Example syntax:

    <myTask><filesetParameter refid="compileUs"/><myTask>
    

    If the referenced fileset is not defined, NAnt will throw an exception - this is proper (expected) behaviour, as the build cannot continue at this point.

    Inside your task, the property would be defined as follows:

    [TaskName("myTask")]
    public class MyTask : Task
    {
      [TaskAttribute("filesetParameter", Required = true)]
      public FileSet FilesetParamter
      { get; set; }
    }