gpt4 book ai didi

azure - 如何让Azure云启动环境变量持续存在

转载 作者:行者123 更新时间:2023-12-03 03:06:30 25 4
gpt4 key购买 nike

对于 Azure 云服务,当您在 ServiceDefinition.csdef 文件中定义启动任务时,您可以选择设置环境变量。它看起来像这样:

<Startup>
<Task commandLine="install.cmd" executionContext="elevated" taskType="simple">
<Environment>
<Variable name="YourEnvironmentVariable" value="YourValue"/>
</Environment>
</Task>
</Startup>

该环境变量似乎仅在其定义的任务持续时间内持续存在(在本例中为运行 install.cmd)。如果您通过 RDP 进入云实例并检查环境变量,您将不会看到它在那里列出。有没有办法让该环境变量持续存在?

最佳答案

Azure 云框架似乎并没有为您提供一种简单的方法来执行此操作,但这是可能的。我通过手动设置 install.cmd 来保留环境变量。就我而言,install.cmd 调用了执行以下操作的 PowerShell 脚本:

# Make the environment variables defined in ServiceDefinition.csdef persist
[Environment]::SetEnvironmentVariable("YourEnvironmentVariable", "$Env:YourEnvironmentVariable", "Machine")

您无需使用 PowerShell 即可完成此任务。它看起来像这样:

setx YourEnvironmentVariable "%YourEnvironmentVariable%" /M

关于azure - 如何让Azure云启动环境变量持续存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43989569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com