在Azure中设置Web应用程序的%PATH%环境变量

8

我正在开发一个Azure Web应用项目。为了让我的应用程序正常工作,我需要在服务器上安装第三方开源软件。我在Azure Web应用中找到的唯一方法是手动复制该软件的所有文件夹到我的项目中,并添加所有必需的环境变量,还需要将几个路径添加到路径系统变量中。 我已经找到了如何添加系统变量,但我无法找到在Azure Web应用中设置路径变量的方法。

1个回答

11
您可以通过 XDT 转换XML Document Transform)来实现此目标。
请查看https://github.com/projectkudu/kudu/wiki/Xdt-transform-samples

添加环境变量

以下代码将注入名为 FOO,值为 BAR 的环境变量,并将文件夹添加到 PATH 中:

<?xml version="1.0"?> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
  <system.webServer> 
    <runtime xdt:Transform="InsertIfMissing">
      <environmentVariables xdt:Transform="InsertIfMissing">
        <add name="FOO" value="BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />    
        <add name="PATH" value="%PATH%;%HOME%\BAR" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />    
      </environmentVariables>
    </runtime> 
  </system.webServer> 
</configuration>

将其放入 d:\home\site\applicationHost.xdt,重新启动 Web 应用程序并在 Kudu (https://sitename.scm.azurewebsites.net/DebugConsole) 中检查新修改的 %PATH%

d:\home>set PATH
Path=D:\home\site\deployments\tools;[...];D:\home\BAR

1
那正是我正在寻找的。 - Farhad

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接