NAnt SDK Documentation - v0.92 |

# SetEnvTask Class

Sets an environment variable or a whole collection of them. Use an empty LiteralValue attribute to clear a variable.

For a list of all members of this type, see SetEnvTask Members.

System.Object
NAnt.Core.Element
NAnt.Core.Task
NAnt.Core.Tasks.SetEnvTask

[Visual Basic]
<TaskName(Name:="setenv")>
Public Class SetEnvTask
Inherits Task
[C#]
[TaskName(Name="setenv")]
public class SetEnvTask : Task

#### Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

#### Remarks

> Note 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 ExecTask and its nested EnvironmentSet element might be a better option.

> Note Expansion of inline environment variables is performed using the syntax of the current platform. So on Windows platforms using the string %PATH% in the LiteralValue attribute will result in the value of the PATH variable being expanded in place before the variable is set.

#### Example

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>

#### Requirements

Namespace: NAnt.Core.Tasks

Assembly: NAnt.Core (in NAnt.Core.dll)

#### See Also

SetEnvTask Members | NAnt.Core.Tasks Namespace