C# - NAnt extension function, Project object
Translations
Englishالعربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
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 Tom Lokhorst (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 Scott Saad
Find More Answers