Open Source .NET Development [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Open Source .NET Development [Electronic resources] - نسخه متنی

Brian Nantz

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید


Extending NAntContrib


If a task is not platform-independent and instead is specific to one operating system or CLI implementation, then the task should be added to NAntContrib. Extending NAntContrib is very similar to extending NAnt, and many of the same principles apply. In fact, many tasks in NAntContrib started out as NAnt tasks.

Enabling Your Task to Handle Multiple Versions of NAnt


If your task in NAntContrib task depends on functionality introduced in a specific version of NAnt, then it may be useful to check the NAnt version in the code of the NAntContrib task.

if(Convert.ToDouble(this.Properties ["nant.version"].ToString()) < 1.1)
{
BuildException("Wrong NAnt Version");
}

MakeIsoFs Task


Cygwin (Appendix C, "Mkisofs Man Page." A common use of mkisofs is to create CDs that are readable on multiple operating systems.

To create an HFS hybrid CD with Rock Ridge extensions of the source directory cd_dir, use the following:

mkisofs -o cd.iso -R cd_dir

So, as you can see in Listing 4.23, the required inputs are the output file name and input directory.

Listing 4.23. The NAnt mkisofs Task Code

[TaskName("mkisofs ")]
public class MkIsoFsTask :

ExternalProgramBase {
int _timeout = Int32.MaxValue;
string _isofilename;
string _inputdir;
bool _rockridge=true;

[TaskAttribute("rockridge")]

[BooleanValidator()]
public bool rockridge {
get { return _rockridge; }
set { _rockridge = value; }
}

[TaskAttribute("isofilename", Required=true)]
public string isofilename {
get { return _isofilename; }
set { _isofilename = value; }
}

[TaskAttribute("inputdir", Required=true)]
public string inputdir {
get { return _inputdir; }
set { _inputdir = value; }
}

[TaskAttribute("timeout")]

[Int32Validator()]
public override int timeout {
get { return _timeout; }
set { _timeout = value; }
}
// The base class calls this to build the command-line string.
public override string ProgramFileName {
get { return " mkisofs "; }
}
// The base class calls this to build the command-line string.
public override string ProgramArguments {
get {
if(!rockridge)
{
return "-o " + isofilename + " " + inputdir ;
}
else
{
return "-o " + isofilename + "-R " + inputdir ;
}
}
protected override void ExecuteTask() {
if(this.Verbose)
{
Log.WriteLine("Creating {0} from directory {1}", isofilename , inputdir);
}
// we'll let the base task do all the work.
base.ExecuteTask();
}
}
}

If I had picked a task that was not a wrapper around an exe, I would have inherited from just Task (like the NAnt task did), and the ExecuteTask would be much more interesting. Take a look at the <mkdir> task code in Listing 4.24 for an example of a task that inherits from Task.

Listing 4.24. NAnt's mkdir Task Code

[TaskName("mkdir")]
public class MkDirTask :

Task {
string _dir = null; // the directory to create

[TaskAttribute("dir", Required=true)]
public string Dir { get { return _dir; } set { _dir = value; } }
protected override void ExecuteTask() {
try {
string directory = Project.GetFullPath(_dir);
if (!Directory.Exists(directory)) {
Log.WriteLine(LogPrefix + "Creating directory {0}", directory);
DirectoryInfo result = Directory.CreateDirectory(directory);
if (result == null) {
string msg = String.Format("Unknown error creating directory '{0
}'", directory);
throw new BuildException(msg, Location);
}
}
} catch (Exception e) {
throw new BuildException(e.Message, Location, e);
}
}
}
}

After building all the projects into a product and using the MSI tasks to create an install, this task can be useful for creating an ISO CDROM image for release to Quality Assurance for testing and eventually to manufacturing for distribution.


    / 275