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.

----- Original Message -----
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.
 

Reply via email to