C# - NAnt extension function, Project object

Is there a way to access the Project object from a NAnt extension function, as can be done from an extension task?

In this example, I want to use the BaseDirectory property inside the Bar function:

[FunctionSet("foo", "Foo")]
public class FooFunctions : FunctionSetBase
{
	public FooFunctions(Project project, PropertyDictionary properties)
		: base(project, properties)
	{
		// When does this constructor gets called?
	}

	[Function("bar")]
	public static string Bar(string name)
	{
		return "Bar!"; // How to get at project.BaseDirectory?
	}
}

I'm new to NAnt extensions, so I don't know if this is even a valid question or if I should approach the problem differently.

This question and answers originated from www.stackoverflow.com
Question by (11/12/2008 2:37:29 PM)

Answer

Great question Tom. The abstract base class, FunctionSetBase, has a property called Project that you can access from the Bar function. However, I noticed that the Bar function is declared static, which is not always necessary (but not wrong).

The following should be completely legal in NAnt world:

Function("bar")]
public string Bar(string name)
{
    string baseDirectory = Project.BaseDirectory;
    return baseDirectory; 
}

Are you seeing any problems?

Answer by

Find More Answers
Related Topics  c#  extension  nant
Related Questions
  • Compile WebSite Project with NAnt

    I have a website project in Visual Studio 2008. I would like to build this website using MSBuild. I use the following command to build the solution: msbuild.exe mysolution.sln /t:Rebuild /v:q …
  • How to create build file for Nant of .Net project

    I have created build files of c# solution(.sln) files as well as the .cs file, but if i want to create a build file of only one project out of more than one project in a solution, i gets error some …
  • Nant not recognizing DateAdd function in the vb file

    In my Nant script even if iam importing all the required namespaces and trying to build the project it is posting declaration errors like dateadd is not declared.Any help with this regard is deeply …
  • NAnt error using solution task to compile .Net framework 3.5 project: Error MSB4127, Error MSB4060

    I run into the error, listed below, when executing a NAnt task that would compile a .Net 3.5 project- with CC.Net: [solution] C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Data.Entity.targets…
  • Nant <csc> build exe System.TypeInitializationException

    I successfully build several projects using < csc target="exe"> . However, when I try to run the generated exe, I get: Unhandled Exception: System.TypeInitializationException: The type init…
  • nant <version> task

    How can I use nant tasks to increment build versions? To be more specific how can I link this up with version numbers in assemblyinfo.cs?
  • Build setup project with NAnt

    I've already got a NAnt build script that builds/runs tests/zips web project together, etc. but I'm working on a basic desktop application. How would I go about build the setup project using NAnt so…
  • Nant "nant.onsuccess" property

    I have a nant file which does the building of my project. Once the build succeeded, I will use the nant.onsuccess property to send mail. In this nant.onsuccess I will call next batch of targets to b…
  • Regarding encrypting web.config using nant

    I have a question that can we run commadnline: aspnet_regiis -pc "DRMBasic" -exp using nant build script. I was trying the following line of code. but somehow this command can't run because the pat…
  • Where is the <import> tag in Nant?

    I want to import another build file into my current project so I can put all common properties in one place. In ant you can simply use: <import file="c:\tools\commonProperties.include" />…