Function开发中从local

Function开发中从local

本文介绍了在VS 2017 Azure Function开发中从local.settings.json读取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在VS 2017中编写Azure函数.我需要设置一些自定义配置参数.我在Values下的local.settings.json中添加了它们.

I am writing an Azure function in VS 2017. I need to set up a few custom configuration parameters. I added them in local.settings.json under Values.

{
   "IsEncrypted":false,
   "Values" : {
      "CustomUrl" : "www.google.com",
       "Keys": {
           "Value1":"1",
           "Value2" :"2"
       }
   }
}

现在,ConfigurationManager.AppSettings["CustomUrl"]返回null.

Now, ConfigurationManager.AppSettings["CustomUrl"] returns null.

我正在使用:

  • .NET Framework 4.7
  • Microsoft.NET.Sdk.Functions 1.0.5
  • System.Configuration.ConfigurationManager 4.4.0
  • Azure.Functions.Cli 1.0.4

我想念什么吗?

推荐答案

首先,正如Mikhail和ahmelsayed所说,我创建了一个示例并对您的 local.settings.json 数据进行了测试.工作正常.

Firstly, I create a sample and do a test with your local.settings.json data, as Mikhail and ahmelsayed said, it works fine.

据我所知,Values集合应该是字典,如果它包含任何非字符串值,则可能导致Azure函数无法从local.settings.json中读取值.

Besides, as far as I know, Values collection is expected to be a Dictionary, if it contains any non-string values, it can cause Azure function can not read values from local.settings.json.

我的测试:

My Test:

ConfigurationManager.AppSettings["CustomUrl"]使用以下local.settings.json返回null.

ConfigurationManager.AppSettings["CustomUrl"] returns null with the following local.settings.json.

{
  "IsEncrypted": false,
  "Values": {
    "CustomUrl": "www.google.com",
    "testkey": {
      "name": "kname1",
      "value": "kval1"
    }
  }
}

这篇关于在VS 2017 Azure Function开发中从local.settings.json读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 07:23