Glen Farrell wrote:

Well, I still don't know what the problem is - but I have found a way around 
it. If I create the task from XML, then it works fine:

 System.Xml.XmlDocument xmlWeb = new System.Xml.XmlDocument();
 xmlWeb.LoadXml("<mkiisdir dirpath=\"" + strWebDir + "\" vdirname=\"" + strWebClass + 
"\"/>");
 NAnt.Contrib.Tasks.Web.CreateVirtualDirectory taskWeb = 
(NAnt.Contrib.Tasks.Web.CreateVirtualDirectory)Project.CreateTask(xmlWeb.ChildNodes[0]);
 taskWeb.Execute();

I don't particularly like doing it this way - not as legible or efficient as 
calling the class directly. But hey, it's just the build process, so not overly 
concerned! If anyone has an idea how to get it working directly though, let me 
know ...

For the record, I was able to get the solution and gac tasks working directly 
without a problem. But the mkiisdir, csc, and wsdl tasks all had to be done 
through XML.
That shouldn't be the case. There might be a property you need to set. Have tried debugging to work out where the null reference exception is coming from ? I know that Clayton Harbor has recently been working on refactoring the solution task to defer to csc the same way you are doing. Maybe he can give some insight or you could look at the code hes been working on on the "SolutionPatchesBranch" :

http://cvs.sourceforge.net/viewcvs.py/nant/nant/src/NAnt.VSNet/?only_with_tag=SolutionPatchesBranch#dirlist

CompilerBase.cs in NAnt.DotNet\Tasks also calls out to the ResgenTask in a 
similar manner and might be a good reference.

Ian


----- Original Message ----- From: Glen Farrell To: nantcontrib-developer@lists.sourceforge.net Sent: Monday, July 18, 2005 1:51 PM
 Subject: [NAntC-Dev] Calling NAnt tasks from code


 Hi, I'm hoping somebody on this list can help me ... I'm trying to write a 
custom NAnt task that combines other tasks. Basically, there's a number of 
tasks that need to be done in order to build one of my projects. Since I'm 
going to have quite a few projects, and don't particularly want a bunch of 
long, almost-identical, scripts, I'd like to combine those tasks into one 
custom task. Some of it really is custom, but there's also a number of tasks 
that already exist. Which of course means that I would like to call those other 
tasks from within my own task (i.e: from C#). Unfortunately, the documentation 
is of course all aimed at people calling them from NAnt script ...

 Now, some of it I've been able to figure out. For example, the following 
performs the solution task (assuming strSolution, strOutputDir, and bDebug have 
all been properly set of course):
   NAnt.VSNet.Tasks.SolutionTask taskSolution = new 
NAnt.VSNet.Tasks.SolutionTask();
   taskSolution.Project = Project;
   taskSolution.SolutionFile = new FileInfo(strSolution);
   taskSolution.OutputDir = new DirectoryInfo(strOutputDir);
   taskSolution.Configuration = (bDebug ? "Debug" : "Release");
   taskSolution.Execute();
 Now where I'm having a problem is the mkiisdir task ... I've tried the 
following code:
   NAnt.Contrib.Tasks.Web.CreateVirtualDirectory taskWeb = new 
NAnt.Contrib.Tasks.Web.CreateVirtualDirectory();
   taskWeb.Project = Project;
   taskWeb.DirPath = new DirectoryInfo(strWebDir);
   taskWeb.VirtualDirectory = strWebClass;
   taskWeb.Execute();
 However, when I try to run the build, I get an error message about "Object 
reference not set to an instance of an object". So what am I doing wrong? Is there 
something more I should be doing to initialize the task? The corresponding NAnt script 
works fine, so I know it's not my IIS setup ...

 Thanks,
 Glen.



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
NAntContrib-Developer mailing list
NAntContrib-Developer@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nantcontrib-developer

Reply via email to