【发布时间】:2019-06-21 21:42:00
【问题描述】:
我正在使用 Azure 函数,但遇到了问题。
我用我的变量声明了一个local.settings.json 文件,如下所示:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"TopicEndpoint": "my endpoint"
}
}
这允许我的天蓝色函数使用以下方法读取设置:
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var myTopic = config["Values:TopicEndpoint"];
这允许我通过以下方式发布变量并将其导出到门户:
func azure functionapp
publish myfunctionapp --publish-local-settings -i
但是,在发布并验证该值在门户的“应用程序设置”中时,“Values:TopicEndpoint”不存在。
为了能够访问它的值,我必须将我的变量直接放在 json 根目录下:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
}
"TopicEndpoint": "my endpoint"
}
这样我就可以在本地开发环境以及 Azure 上安全地使用 config['TopicEndpoint']。但是,这违背了--publish-local-settings -i 的目的,因为它只导出在“值”键下找到的值,所以我必须手动创建所有设置。
你知道为什么会发生这种情况,或者我是否遗漏了什么?
【问题讨论】:
-
部署时是否显示
App setting AzureWebJobsStorage is different between azure and local.settings.json Would you like to overwrite value in azure? [yes/no/show]? -
不,它在部署期间没有显示警告,但我肯定门户上的值在 Values 键中声明时得到了更新。
-
也许你可以试试
--overwrite-settings [-y]和--publish-local-settings -i。你是什么意思门户上的值在 Values 键中声明时得到更新?你之前说过Values:TopicEndpoint不存在。 -
确定不存在。它作为应用程序设置更新,只能通过执行 config["TopicEndpoint"] 读取,并且不在“Values”键内
标签: azure azure-functions