从 VS 2017 Azure Function 开发中的 local.settings.json 读取值 [英] Read values from local.settings.json in VS 2017 Azure Function development
问题描述
我正在 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 框架 4.7
- Microsoft.NET.Sdk.Functions 1.0.5
- System.Configuration.ConfigurationManager 4.4.0
- Azure.Functions.Cli 1.0.4
我错过了什么吗?
推荐答案
首先,我创建了一个示例并使用您的 local.settings.json 数据进行测试,正如 Mikhail 和 ahmelsayed 所说,它工作正常.
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.
我的测试:
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 读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!