SetEnvTask Class

Summary

Sets an environment variable or a whole collection of them. Use an empty NAnt.Core.Tasks.SetEnvTask.LiteralValue attribute to clear a variable.
Assembly
NAnt.Core.dll
Namespace
NAnt.Core.Tasks
Interfaces
Base Types
graph BT Type-->Base0["Task"] click Base0 "/api/NAnt.Core/Task" Base0-->Base1["Element"] click Base1 "/api/NAnt.Core/Element" Base1-->Base2["Object"] Type-.->Interface0["IConditional"] click Interface0 "/api/NAnt.Core/IConditional" Type["SetEnvTask"] class Type type-node

Syntax

[TaskName("setenv")]
public class SetEnvTask : Task, IConditional

Examples

Set the MONO_PATH environment variable on a *nix platform.

<setenv name=="MONO_PATH" value="/home/jimbob/dev/foo:%MONO_PATH%"/>

Set a collection of environment variables. Note the nested variable used to set var3.

<setenv>
        <variable name="var1" value="value2" />
        <variable name="var2" value="value2" />
        <variable name="var3" value="value3:%var2%" />
</setenv>

Set environment variables using nested path elements.

<path id="build.path">
       <pathelement dir="c:/windows" />
       <pathelement dir="c:/cygwin/usr/local/bin" />
   </path>
<setenv>         
        <variable name="build_path" >
               <path refid="build.path" />
        </variable>
        <variable name="path2">
           <path>
               <pathelement dir="c:/windows" />
               <pathelement dir="c:/cygwin/usr/local/bin" />
           </path>
        </variable>
</setenv>

Remarks

Variables will be set for the current NAnt process and all child processes that NAnt spawns (compilers, shell tools, etc). If the intention is to only set a variable for a single child process, then using the NAnt.Core.Tasks.ExecTask and its nested NAnt.Core.Tasks.ExecTask.EnvironmentSet element might be a better option.
Expansion of inline environment variables is performed using the syntax of the current platform. So on Windows platforms using the string %PATH% in the NAnt.Core.Tasks.SetEnvTask.LiteralValue attribute will result in the value of the PATH variable being expanded in place before the variable is set.

Attributes

Type Description
TaskNameAttribute Indicates that class should be treated as a task.

Properties

Name Value Summary
CustomXmlProcessing bool
Gets a value indicating whether the element is performing additional processing using the NAnt.Core.Element.XmlNode that was used to initialize the element.
Inherited from Element
Directory DirectoryInfo
The value for a directory-based environment variable. NAnt will convert it to an absolute path.
EnvironmentVariables EnvironmentVariableCollection
Gets or sets the environment variables.
EnvName string
The name of a single Environment variable to set
FailOnError bool
Determines if task failure stops the build, or is just reported. The default is true.
Inherited from Task
File FileInfo
The value for a file-based environment variable. NAnt will convert it to an absolute filename.
IfDefined bool
If true then the task will be executed; otherwise, skipped. The default is true.
Inherited from Task
LiteralValue string
The literal value for the environment variable.
Location Location
Gets or sets the location in the build file where the element is defined.
Inherited from Element
LogPrefix string
The prefix used when sending messages to the log.
Inherited from Task
Name string
The name of the task.
Inherited from Task
NamespaceManager XmlNamespaceManager
Gets or sets the System.Xml.XmlNamespaceManager.
Inherited from Element
Parent Object
Gets or sets the parent of the element.
Inherited from Element
Path PathSet
The value for a PATH like environment variable. You can use : or ; as path separators and NAnt will convert it to the platform's local conventions.
Project Project
Gets or sets the NAnt.Core.Element.Project to which this element belongs.
Inherited from Element
Properties PropertyDictionary
Gets the properties local to this NAnt.Core.Element and the NAnt.Core.Element.Project.
Inherited from Element
Threshold Level
Gets or sets the log threshold for this NAnt.Core.Task. By default the threshold of a task is NAnt.Core.Level.Debug, causing no messages to be filtered in the task itself.
Inherited from Task
UnlessDefined bool
Opposite of NAnt.Core.Task.IfDefined. If false then the task will be executed; otherwise, skipped. The default is false.
Inherited from Task
Verbose bool
Determines whether the task should report detailed build log messages. The default is false.
Inherited from Task
XmlNode XmlNode
Gets or sets the XML node of the element.
Inherited from Element

Methods

Name Value Summary
CopyTo(Element) void
Copies all instance data of the NAnt.Core.Element to a given NAnt.Core.Element.
Inherited from Element
Execute() void
Executes the task unless it is skipped.
Inherited from Task
ExecuteTask() void
Set the environment variables
GetAttributeConfigurationNode(FrameworkInfo, string) XmlNode
Locates the XML node for the specified attribute in either the configuration section of the extension assembly or the.project.
Inherited from Task
GetAttributeConfigurationNode(XmlNode, FrameworkInfo, string) XmlNode
Inherited from Element
GetLocation() Location
Retrieves the location in the build file where the element is defined.
Inherited from Element
Initialize() void
Checks whether the task is initialized with valid attributes.
Initialize(XmlNode) void
Performs default initialization.
Inherited from Element
InitializeBuildElement(Element, XmlNode, Element, Type) Element
Initializes the build element.
Inherited from Element
static
InitializeElement(XmlNode) void
Derived classes should override to this method to provide extra initialization and validation not covered by the base class.
Inherited from Element
InitializeTask(XmlNode) void
Initializes the task.
Inherited from Task
InitializeTaskConfiguration() void
Initializes the configuration of the task using configuration settings retrieved from the NAnt configuration file.
Inherited from Task
InitializeXml(XmlNode, PropertyDictionary, FrameworkInfo) void
Initializes all build attributes and child elements.
Inherited from Element
IsLogEnabledFor(Level) bool
Determines whether build output is enabled for the given NAnt.Core.Level.
Inherited from Task
Log(Level, string) void
Logs a message with the given priority.
Inherited from Task
Log(Level, string, Object[]) void
Logs a formatted message with the given priority.
Inherited from Task