Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure Powershell-无需关闭应用程序即可设置环境变量_Azure_Powershell_Environment Variables - Fatal编程技术网

Azure Powershell-无需关闭应用程序即可设置环境变量

Azure Powershell-无需关闭应用程序即可设置环境变量,azure,powershell,environment-variables,Azure,Powershell,Environment Variables,我认为这是不可能的,但在开发软件时,获取最新的环境变量是一个很大的难题 例如,我有一个psake脚本,用于更新我的应用程序所需的环境变量: [System.Environment]::SetEnvironmentVariable($myConfig, $myValue, 'Process') [System.Environment]::SetEnvironmentVariable($myConfig, $myValue, [System.EnvironmentVariableTarget]::M

我认为这是不可能的,但在开发软件时,获取最新的环境变量是一个很大的难题

例如,我有一个psake脚本,用于更新我的应用程序所需的环境变量:

[System.Environment]::SetEnvironmentVariable($myConfig, $myValue, 'Process')
[System.Environment]::SetEnvironmentVariable($myConfig, $myValue, [System.EnvironmentVariableTarget]::Machine)
这个环境变量可能每天/每周都会发生变化,因为它基于旋转的Azure基础设施

在Visual Studio中,我的应用程序依赖此环境变量进行配置,在退出VS并重新打开它之前,它将不会成功运行(因此“机器”设置的环境变量现在是最新的)


是否可以采取任何措施防止每次Windows上的环境变量发生变化时,我们不得不关闭并重新打开所有内容?

当前环境变量可以从注册表中读取

Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name myConfig
作为一种解决方法,您可以从注册表读取值,然后再次设置环境变量以更新会话,而无需重新打开

$myConfig = "myConfig"
$reg = Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name myConfig
$myValue = $reg.myConfig
[System.Environment]::SetEnvironmentVariable($myConfig, $myValue, 'Process')
[System.Environment]::SetEnvironmentVariable($myConfig, $myValue, [System.EnvironmentVariableTarget]::Machine)

这是任何应用程序(包括powershell窗口),因为它们都需要卸载才能看到环境变量的变化。您能告诉我们有关该应用程序的更多信息吗?它是如何部署的(Azure函数、Web应用程序、Worker、API?),涉及哪些组件,环境变量值来自何处?我发布了答案
refreshenv
,效果非常好,但很明显,这是一个带巧克力的突击队。