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
Configuration Microsoft Azure:如何将配置设置公开为环境变量?_Configuration_Azure_Environment Variables - Fatal编程技术网

Configuration Microsoft Azure:如何将配置设置公开为环境变量?

Configuration Microsoft Azure:如何将配置设置公开为环境变量?,configuration,azure,environment-variables,Configuration,Azure,Environment Variables,我尝试将其添加到我的ServiceDefinition.csdef文件: <WorkerRole ...><Runtime><Environment> <Variable name="AZURE_STORAGE_ACCOUNT"> <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSet

我尝试将其添加到我的ServiceDefinition.csdef文件:

<WorkerRole ...><Runtime><Environment>
    <Variable name="AZURE_STORAGE_ACCOUNT">
      <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='AZURE_STORAGE_ACCOUNT']/@value" />
    </Variable>
</Environment></Runtime></WorkerRole>

配置似乎是正确的。如果您能确保使用的是最新的SDK,那就更好了。xPath功能在Windows Azure SDK 1.5及更高版本中可用

致以最良好的祝愿


徐明。

您是否错过了该设置的声明?我在您的
.csdef
中没有看到合适的元素,类似于
。您需要
.csdef
中的一个,然后您仍然需要
.cscfg
中包含该值的一个


如果您使用的是Visual Studio,那么如果您使用其属性视图,它应该为您编辑这两个文件。(只需双击该角色,然后单击周围以进入配置设置并添加新设置。)

我尝试了博客中提到的不同选项,例如在.cscfg和.csdef中都包含该设置。但是,它似乎不起作用。 另外,还有其他Xpath查询,如

      <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/@id"/>

工作正常

最后,我发现使用的变量名不同:

在cscfg中,我有:

<Setting name="WFFEPeriodicRestartTime" value="168:00:00" />

在csdef中,我有:

  <ConfigurationSettings>
      <Setting name="PeriodicRestartTime" />
   </ConfigurationSettings>

。。。。



将csdef更改为:

<ConfigurationSettings>
      <Setting name="WFFEPeriodicRestartTime" />
   </ConfigurationSettings>

。。。。




现在它似乎工作正常了

在这里遇到了相同的问题,因为我试图通过这里提供的示例读取配置值:-在这个过程中丢失了相当多的脑细胞

诀窍在于,这并不意味着您从web.config(我就是这样误读它的)读取配置值,而是从cscfg文件中的设置读取

对于云服务,您有一个csdef文件,适用于所有云服务配置,但每个环境都有一个cscfg。在我的场景中,我有用于DEV、QA、Prod的cscfg,我需要根据环境设置不同的变量

因此,对于OP的问题,当您尝试执行“RoleEnvironment/CurrentInstance/ConfigurationSettings…”语句并获取无效的xpath值时,实际上是说“嘿,我找不到这个值”

如何让奇迹发生:

您的csdef文件需要以下内容:

<ConfigurationSettings>
    <Setting name="AZURE_STORAGE_ACCOUNT" />
</ConfigurationSettings>

然后,您的cscfg需要:

<ConfigurationSettings>
      <Setting name="AZURE_STORAGE_ACCOUNT" value="Some Secret Value" />
</ConfigurationSettings>

出于我的目的,我试图在startup.cmd文件中使用此值,因此我能够将以下内容添加到我的csdef启动任务中

<Startup>
  <Task commandLine="Startup.cmd" executionContext="elevated" taskType="simple">
    <Environment>
      <Variable name="AZURE_STORAGE_ACCOUNT">
        <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='AZURE_STORAGE_ACCOUNT']/@value" />
      </Variable>
    </Environment>
  </Task>
</Startup>


然后,在my startup.cmd中,您可以将该值引用为%%AZURE\u STORAGE\u ACCOUNT%%

这个问题本身就足以让我达到目标,并且有足够的内置答案+1.
 <Variable name="WFFEPeriodicRestartTime">
            <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='WFFEPeriodicRestartTime']/@value" />
          </Variable>
<ConfigurationSettings>
    <Setting name="AZURE_STORAGE_ACCOUNT" />
</ConfigurationSettings>
<ConfigurationSettings>
      <Setting name="AZURE_STORAGE_ACCOUNT" value="Some Secret Value" />
</ConfigurationSettings>
<Startup>
  <Task commandLine="Startup.cmd" executionContext="elevated" taskType="simple">
    <Environment>
      <Variable name="AZURE_STORAGE_ACCOUNT">
        <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='AZURE_STORAGE_ACCOUNT']/@value" />
      </Variable>
    </Environment>
  </Task>
</Startup>