EnvironmentVariable Class

MSBuild Extension Pack

EnvironmentVariable Class MSBuild Extension Pack Help 4.0.12.0
Valid TaskActions are:

Get (Required: Variable Optional: Target Output: Value)

Set (Required: Variable, Value Optional: Target)

Remote Execution Support: For Get TaskAction only

Inheritance Hierarchy

SystemObject  Microsoft.Build.UtilitiesTask
    MSBuild.ExtensionPackBaseTask
      MSBuild.ExtensionPack.ComputerEnvironmentVariable

Namespace: MSBuild.ExtensionPack.Computer
Assembly: MSBuild.ExtensionPack (in MSBuild.ExtensionPack.dll) Version: 4.0.0.0

The EnvironmentVariable type exposes the following members.

Constructors

  NameDescription
Public methodEnvironmentVariable
Top
Properties

  NameDescription
Public propertyTarget
Machine, Process or User. Defaults to Process
Public propertyValue
Gets or sets the value. May be a string array for Get. If Value is not passed or empty for Set, the environment variable is deleted.
Public propertyVariable
The name of the Environment Variable to get or set.
Top
Examples

<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
        <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
    </PropertyGroup>
    <Import Project="$(TPath)"/>
    <Target Name="Default">
        <!-- Set an environment variable. Note how special characters need to be escaped (http://msdn.microsoft.com/en-us/library/ms228186(VS.80).aspx) -->
        <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Set" Variable="PATH" Value="$(VCInstallDir)Common7\IDE%3B$(VCInstallDir)VC\BIN%3B$(VCInstallDir)Common7\Tools%3B$(VCInstallDir)Common7\Tools\bin%3B$(VCInstallDir)VC\PlatformSDK\bin%3B$(SDKInstallDir)bin%3B$(PATH)"/>
        <!-- Set a new Environment Variable. The default target is Process -->
        <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Set" Variable="ANewEnvSample" Value="bddd"/>
        <!-- Get the Environment Variable -->
        <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Get" Variable="ANewEnvSample">
            <Output PropertyName="EnvValue" TaskParameter="Value"/>
        </MSBuild.ExtensionPack.Computer.EnvironmentVariable>
        <Message Text="Get: $(EnvValue)"/>
        <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Set" Variable="ANewEnvSample" Value="newddd"/>
        <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Get" Variable="ANewEnvSample">
            <Output PropertyName="EnvValue" TaskParameter="Value"/>
        </MSBuild.ExtensionPack.Computer.EnvironmentVariable>
        <Message Text="Get: $(EnvValue)"/>
        <!-- Set a new Environment Variable on a remote machine -->
        <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Set" Variable="ANewEnvSample" Value="bddd" MachineName="MediaHub"/>
        <!-- Get an Environment Variable from a remote machine -->
        <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Get" Variable="INOCULAN" Target="Machine" MachineName="machinename" UserName="Administrator" UserPassword="passw">
            <Output PropertyName="EnvValue" TaskParameter="Value"/>
        </MSBuild.ExtensionPack.Computer.EnvironmentVariable>
        <Message Text="INOCULAN Get: $(EnvValue)"/>
        <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Get" Variable="FT" Target="User" MachineName="machinename" UserName="Administrator" UserPassword="passw">
            <Output PropertyName="EnvValue" TaskParameter="Value"/>
        </MSBuild.ExtensionPack.Computer.EnvironmentVariable>
        <Message Text="FT Get: $(EnvValue)"/>
    </Target>
</Project>
See Also

Reference