1

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?

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
  • Generally, tasks should not "depend" on filesets/properties, but take explicit parameters. The fileset won't need redeclaration, as it can be included via a simple refid reference. – skolima Dec 19 '11 at 10:34
  • Not sure I understand you correctly. I reference the fileset with refid, but if the fileset is not defined somewhere, it will shoot with the "undefined" error. – Yan Sklyarenko Dec 19 '11 at 11:42
  • BTW, I have problems trying to pass filesets as parameters - it seems NAnt can't expand it back to fileset in the task, treating it as a string literal. Is it something known? Or am I just falling into the holes all newbies fall into? :) – Yan Sklyarenko Dec 19 '11 at 11:44
  • What I meant was: ``. If the referenced fileset is not defined here, then a exception is proper behaviour, as the build cannot continue. – skolima Dec 19 '11 at 11:49
  • So, your recommendation is to add a parameter of type 'fileset' to the custom task, and live with the expected behavior when it fails if the fileset is not passed. Right? And I take it there's no way to find out whether fileset is defined before it fails, right? – Yan Sklyarenko Dec 19 '11 at 12:03
  • Exactly, that's what I would do. – skolima Dec 19 '11 at 12:33
  • Thanks! It's helpful, could you wrap it into an answer so that I could accept it? :) – Yan Sklyarenko Dec 19 '11 at 12:52

1 Answers1

1

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; }
}
skolima
  • 31,963
  • 27
  • 115
  • 151