在启动后重新载入C#中的环境变量 [英] Reload Environment Variables in C# after launch

查看:152
本文介绍了在启动后重新载入C#中的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们收到了一个新的代码库,它使用环境变量。他们指的是项目根,资产,不同工具等等,而不是最理想的情况,但它是有效的。然而,当它来到尝试运行我们的自动化构建的时候,它变得巨大的痛苦。

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似乎在创建进程时实例化环境变量,并且不会再次刷新这些值。我们希望能够通过一系列项目运行自动构建系统,并依次构建每个项目。这需要调用更改这些值的项目切换器。当这样做完成时,更改不会反映在当前正在运行的构建过程中。

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.

有谁知道任何可以用来强制执行的C#命令/函数/调用项目切换器后重新加载环境变量?

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?

推荐答案

有重载的 System.Environment.GetEnvironmentVariable System.Environment.GetEnvironmentVariable 检索:


...当前进程环境变量的值或从当前用户或本地机器的Windows操作系统注册表项。

... 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.

这篇关于在启动后重新载入C#中的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆