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.
From stackoverflow
-
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?
Tom Lokhorst : That works perfectly, thanks! For anyone interested: The constructor for FooFunctions is called on each invocation of the (non-static) Bar method.
0 comments:
Post a Comment