【问题标题】:Azure configuration settings and Microsoft.WindowsAzure.CloudConfigurationManagerAzure 配置设置和 Microsoft.WindowsAzure.CloudConfigurationManager
【发布时间】:2012-07-18 18:49:12
【问题描述】:

显然Microsoft.WindowsAzure.CloudConfigurationManager.GetSettings 将首先查看 ServiceConfiguration.*.cscfg,然后返回到 web.config 和 app.config。

但是 - 这在 web/app .config 中应该是什么格式?

例如让Microsoft.WindowsAzure.CloudConfigurationManager.GetSettings("Foo") 从 app.config 中获取 XML 是什么样的?

【问题讨论】:

  • 从您提供的 msdn 链接中:“CloudConfigurationManager 只能读取 appSettings 标记中的配置设置。如果您的配置设置在不同的标记中,调用 GetSetting 将返回 Null。”

标签: c# azure configuration-files


【解决方案1】:

它只是一个appSettings key/value

<configuration>
  <appSettings>
    <add key="Foo" value="AzureSetting"/>
  </appSettings>
</configuration>

【讨论】:

  • 这就是我的想法,但它对我不起作用。您确定使用 AZURE CloudConfigManager 吗? (在我开始挖掘之前检查一下)
  • 嗯 - ConfigurationManager.AppSettings 也不起作用,所以显然还有其他问题 - 谢谢!
  • 一个问题,如果webrole或worker角色引用了一个程序集,CloudconfigurationManager会读取该程序集的app.config中的appsettings吗?
【解决方案2】:

您需要将设置添加到 ServiceDefinition.csdef 和 ServiceConfiguration.cscfg

例如:ServiceDefinition.csdef

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="WindowsAzure1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2012-05.1.7">
    <WebRole name="WebRole1" vmsize="Small">
        <ConfigurationSettings>
            <Setting name="Foo"/>
        </ConfigurationSettings>
        :
    </WebRole>
</ServiceDefinition>

例如:ServiceConfiguration.cscfg

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="WindowsAzure1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="1" osVersion="*" schemaVersion="2012-05.1.7">
  <Role name="WebRole1">
    <Instances count="1" />
    <ConfigurationSettings>
        <Setting name="Foo" value="val"/>
    </ConfigurationSettings>
  </Role>
</ServiceConfiguration>

【讨论】:

  • 不需要这样做。来自问题中的 msdn link:“在 Windows Azure 之外的环境中运行的 .NET 应用程序通常将配置设置存储在 web.config 或 app.config 文件中。CloudConfigurationManager 类使您能够从适当的配置文件中读取,无论运行代码的环境。"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-28
  • 2014-08-05
相关资源
最近更新 更多