Working with environment variables
Environment variables are system and user-definable values that can affect the way running processes behave. They are commonly used to set options like toggling between development and production configurations in ASP.NET Core web projects, or to pass values needed by a process like service keys and passwords for database connection strings.Environment variables on Windows can be set at three scope levels: machine (aka system), user, and process. The methods for setting and getting environment variables assume process scope level by default and have overloads to specify the EnvironmentVariableTarget
of Process
, User
, and Machine
, as shown in Table 9.7:
Method | Description |
GetEnvironmentVariables |
Returns an IDictionary of all environment variables at a specified scope level or for the current process by default. |
GetEnvironmentVariable |
Returns the value for a named environment variable. |
SetEnvironmentVariable |
Sets the value for a named environment... |