Description
Add support for setting the environment variable to an empty value in Environment.SetEnvironment and ProcessInfo.Environment APIs.
Version
.NET 9 Preview 6
Previous behavior
Both Environment.SetEnvironment("TEST", string.Empty) and Environment.SetEnvironment("TEST", null) deleted the environment variable.
Both ProcessInfo.Environment["TEST"] = string.Empty and ProcessInfo.Environment["TEST"] = null set the environment variable in the child process to an empty value.
New behavior
Environment.SetEnvironment("TEST", string.Empty) sets the environment variable value to an empty value. Environment.SetEnvironment("TEST", null) behavior is unchanged, it still deletes the environment variable.
ProcessInfo.Environment["TEST"] = null deletes the environment variable. ProcessInfo.Environment["TEST"] = string.Empty behavior is unchanged, it still sets the environment variable the environment variable value to an empty value.
Type of breaking change
Reason for change
Before this change, it was not possible to use Environment.SetEnvironment to set the environment variable to an empty value that is a valid environment variable value on all supported platforms.
Recommended action
Change code to pass null instead of string.Empty as the value argument to Environment.SetEnvironment API to delete the environment variable.
Change code to pass string.Empty instead of null as the value to ProcessStartInfo.Environment, ProcessStartInfo.EnvironmentVariables APIs to set the environment variable to an empty value.
Feature area
Core .NET libraries
Affected APIs
Environment.SetEnvironmentVariable, ProcessStartInfo.Environment, ProcessStartInfo.EnvironmentVariables
Associated WorkItem - 281896
Description
Add support for setting the environment variable to an empty value in
Environment.SetEnvironmentandProcessInfo.EnvironmentAPIs.Version
.NET 9 Preview 6
Previous behavior
Both
Environment.SetEnvironment("TEST", string.Empty)andEnvironment.SetEnvironment("TEST", null)deleted the environment variable.Both
ProcessInfo.Environment["TEST"] = string.EmptyandProcessInfo.Environment["TEST"] = nullset the environment variable in the child process to an empty value.New behavior
Environment.SetEnvironment("TEST", string.Empty)sets the environment variable value to an empty value.Environment.SetEnvironment("TEST", null)behavior is unchanged, it still deletes the environment variable.ProcessInfo.Environment["TEST"] = nulldeletes the environment variable.ProcessInfo.Environment["TEST"] = string.Emptybehavior is unchanged, it still sets the environment variable the environment variable value to an empty value.Type of breaking change
Reason for change
Before this change, it was not possible to use
Environment.SetEnvironmentto set the environment variable to an empty value that is a valid environment variable value on all supported platforms.Recommended action
Change code to pass
nullinstead ofstring.Emptyas the value argument toEnvironment.SetEnvironmentAPI to delete the environment variable.Change code to pass
string.Emptyinstead of null as the value toProcessStartInfo.Environment,ProcessStartInfo.EnvironmentVariablesAPIs to set the environment variable to an empty value.Feature area
Core .NET libraries
Affected APIs
Environment.SetEnvironmentVariable,ProcessStartInfo.Environment,ProcessStartInfo.EnvironmentVariablesAssociated WorkItem - 281896