In full .NET we can pass EnvironmentVariableTarget
enum to Environment.SetEnvironmentVariable
call:
public enum EnvironmentVariableTarget
{
Process,
User,
Machine
}
With User
or Machine
options we can set a user-wide or system-wide variable which stays live after application end:
Environment.SetEnvironmentVariable("foo", "bar", EnvironmentVariableTarget.User);
...
> echo %foo%
bar
However, Environment.SetEnvironmentVariable
doesn't accept the variable target in .NET Core. Even XML comment for this method says:
Creates, modifies, or deletes an environment variable stored in the current process.
How to set an user-wide or machine-wide environment variable in .NET Core-targeted app? Only a crossplatform solution makes sense (at least Windows and Linux).