ToolTask.EnvironmentOverride Property
Note: This API is now obsolete.
Gets a set of environment variable name-value pairs. Designed to be overridden in a custom task class (derived from ToolTask) to return a set of new or altered environment variables to create the execution context of the associated tool.
MSBuild is now included in Visual Studio instead of the .NET Framework. You can use MSBuild 12.0 side-by-side with versions previously deployed with the .NET Framework.For more information, see What's New in MSBuild 12.0.
Namespace: Microsoft.Build.Utilities
Assembly: Microsoft.Build.Utilities.Core (in Microsoft.Build.Utilities.Core.dll)
Syntax
'Declaration
<ObsoleteAttribute("Use EnvironmentVariables property")> _
Protected Overridable ReadOnly Property EnvironmentOverride As StringDictionary
[ObsoleteAttribute("Use EnvironmentVariables property")]
protected virtual StringDictionary EnvironmentOverride { get; }
[ObsoleteAttribute(L"Use EnvironmentVariables property")]
protected:
virtual property StringDictionary^ EnvironmentOverride {
StringDictionary^ get ();
}
[<ObsoleteAttribute("Use EnvironmentVariables property")>]
abstract EnvironmentOverride : StringDictionary with get
[<ObsoleteAttribute("Use EnvironmentVariables property")>]
override EnvironmentOverride : StringDictionary with get
function get EnvironmentOverride () : StringDictionary
Property Value
Type: StringDictionary
Returns a set of environment variables. Each dictionary key is the name of the environment variable to override and the dictionary value is the value to set for that environment variable. The default implementation of EnvironmentOverride returns null.
Remarks
The ExecuteTool method passes these environment variables to the StartInfo of the process in which the tool executes. Any environment variables not included in the EnvironmentOverride dictionary are inherited from the process in which the ExecuteTool method executes.
Examples
using System;
using Microsoft.Build.Utilities;
using System.Collections.Specialized;
/// <summary>
/// CustomToolTask overrides the EnvironmentOverride property of ToolTask to add a directory
/// to the Path environment variable of the process being executed
/// </summary>
abstract class CustomToolTask : ToolTask
{
protected override StringDictionary EnvironmentOverride
{
get
{
string newPath = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Process) + @";C:\MyDirectory";
StringDictionary result = new StringDictionary();
result.Add("Path", newPath);
return result;
}
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see dd66cd4c-b087-415f-9c3e-94e3a1835f74.