门户网站和本地之间的Azure功能设置不一致 [英] Azure Functions settings not consistent betwen portal and local

查看:49
本文介绍了门户网站和本地之间的Azure功能设置不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Azure函数,并且有问题. 我用变量声明了一个local.settings.json文件,如下所示:

Im working with Azure functions and have a problem. I declared a local.settings.json file with my variables as follows:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "TopicEndpoint": "my endpoint"
  }  
}

这允许我的azure函数使用以下命令读取设置:

This allows my azure function to read the settings using:

var config = new ConfigurationBuilder()
        .SetBasePath(context.FunctionAppDirectory)
        .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
        .AddEnvironmentVariables()
        .Build();
var myTopic = config["Values:TopicEndpoint"];

这使我可以通过以下方式发布变量并将其导出到门户:

This allows me to publish and export my variables to the portal via:

func azure functionapp publish myfunctionapp --publish-local-settings -i

func azure functionapp publish myfunctionapp --publish-local-settings -i

但是,在发布并验证该值在门户网站的应用程序设置"中时,"Values:TopicEndpoint"不存在.

However, upon publishing and verifying that the value is in the 'Application Settings' in the portal, the "Values:TopicEndpoint" doesn't exist.

为了能够访问其值,我必须将变量直接放在json根下:

In order to be able to access its value i have to put my variables directly under the json root:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
  }  
  "TopicEndpoint": "my endpoint"
}

这样,我可以在本地开发环境以及Azure上安全地使用config['TopicEndpoint'].但是,这违反了--publish-local-settings -i的目的,因为它仅导出在值"键下找到的值,因此我必须手动创建所有设置.

That way I can safely use config['TopicEndpoint'] both in my local development environment, as well as on Azure. However, this defeats the purpose of the --publish-local-settings -i as it only exports the values found under the 'Values' key, so I have to create all my settings manually.

您知道为什么会发生这种情况,或者我可能缺少什么吗?

Do you know why this happens or if maybe Im missing something?

推荐答案

我发现了问题. 问题是我在这里建议添加一个单独的secret.settings.json https://www.tomfaltesek.com/azure -functions-local-settings-json-and-source-control/ 因此,我正在像这样加载我的配置:

I found the issue. The problem was that I was adding a separate secret.settings.json as suggested here https://www.tomfaltesek.com/azure-functions-local-settings-json-and-source-control/ Therefore I was loading my configurations like this:

var config = new ConfigurationBuilder()
        .SetBasePath(context.FunctionAppDirectory)
        .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
        .AddJsonFile("secret.settings.json", optional: true, reloadOnChange: true)
        .AddEnvironmentVariables()
        .Build();

我的本​​地设置文件如下:

My local settings file looked like this:

{
  "Values": {
      "TopicEndpoint": "my endpoint"
  }  
}

我的秘密设置是这样的:

And my secret settings like this:

{
  "Values": {
      "TopicKey": "my key"
  }  
}

这引起了冲突,因此我需要从secret.settings.json中删除"Values"键,使其看起来像这样:

This caused a conflict so I needed to remove the 'Values' key from the secret.settings.json so that it looked like this:

{
  "TopicKey": "my key"
}

这样,我既可以使用func azure functionapp publish myfunctionapp --publish-local-settings -i在本地设置文件中部署值,也可以将这两个文件用作环境变量.

This way I am able to both use func azure functionapp publish myfunctionapp --publish-local-settings -i to deploy the values inside my local settings file and use both files as environment variables.

这篇关于门户网站和本地之间的Azure功能设置不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆