Set environment variables in Unix/Linux environment with .NET Core

Viewed 3604

Is there a way to set an environment variable on a Unix/Linux machine (not process) using .NET Core?

I noticed that I can use Environment.SetEnvironmentVarible for Windows, however, after searching I haven't found an equivalent for a Unix/Linux system.

1 Answers

Environment.SetEnvironmentVariable also works on Linux, etc.

But be beware only the current process environment variables are set, and not machine or user environment variables like on Windows:

On .NET Core on macOS and Linux systems, calls to the SetEnvironmentVariable(String, String, EnvironmentVariableTarget) method with a value of EnvironmentVariableTarget.Machine or EnvironmentVariableTarget.User are ignored.

From Environment.SetEnvironmentVariable Method.

Related