Reloading environment variables in C # after startup

We got a new code base that uses environment variables everywhere. They point to things like the root of a project, assets, various tools, etc. Not the most ideal situation, but it works. However, when it comes time to try and run our automatic build, it becomes a huge pain.

Windows seems to be an instance of environment variables when creating the process and does not update these values ​​again. We would like our automatic assembly system to go through the list of projects and build them sequentially. To do this, call the project switch, which changes these values. However, when this is done, the changes are not reflected in the current start of the build process.

Does anyone know of any C # / etc commands / functions that can be used to force reload of environment variables after calling the project switch?

+3
source share
4 answers

There are overloads of System.Environment.GetEnvironmentVariable and System.Environment.GetEnvironmentVariable that retrieve:

... the value of the environment variable from the current process or from the registry key of the Windows operating system for the current user or local machine.

If your changes affect the registry in these areas, this may work for you.

+7
source

MSDN:

" - , . , ".

, (, Environment.SetEnvironmentVariable ProcessStartInfo.EnvironmentVariables).

+4

(cmd.exe), , cmd.exe . cmd.exe, . ( , , ).

, .NET. AppDomain , .

, , , , . , , .

, , , , , .

+1

. , .

The only way to change the process environment is to process the process itself. Any information that must be transferred between two running processes must be in the form of IPC .

For example, it might be better to read the corresponding variables from a file or database rather than from the environment. The database is certainly simpler because it simplifies transaction and synchronization.

+1
source

Source: https://habr.com/ru/post/1716615/


All Articles