Reload Environment Variables in C# after launch
.net, build-automation, c#, environment-variables
Solution
There are overloads of System.Environment.GetEnvironmentVariable and System.Environment.GetEnvironmentVariable that retrieve :
... the value of an environment variable from the current process or from the Windows operating system registry key for the current user or local machine.
If your changes affect the registry in the areas specified, this might work for you.
Problem
We received a new code base that uses environment variables all over the place. They point to things like the project root, assets, different tools, etc. Not the most ideal situation but it works. However, when it comes time to try and run our automated build it becomes a giant pain. Windows seems to instance the environment variables when a process is created and does not refresh those values again. We would like to be able to have our Automated Build System run through a list of projects and build each one sequentially. This requires calling a project switcher which changes those values. When this is done however the changes are not reflected in the currently running build process. Does anyone know of any C# commands/functions/etc that can be used to force the environment variables to reload after the call to project switcher has been made?