[Breaking change]: Support environment variables with empty value #41471
Labels
breaking-change
Indicates a .NET Core breaking change
🏁 Release: .NET 9
Work items for the .NET 9 release
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
Pri1
High priority, do before Pri2 and Pri3
📌 seQUESTered
Identifies that an issue has been imported into Quest.
Description
Add support for setting the environment variable to an empty value in
Environment.SetEnvironment
andProcessInfo.Environment
APIs.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.Empty
andProcessInfo.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 ofstring.Empty
as the value argument toEnvironment.SetEnvironment
API to delete the environment variable.Change code to pass
string.Empty
instead of null as the value toProcessStartInfo.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
The text was updated successfully, but these errors were encountered: