在Mac上使用VS2017进行调试时,Azure Function无法读取/访问local.settings.json

bbqchickenrobot

在使用VS2017 for Mac在本地调试Azure函数时尝试从local.settings.json配置文件中读取时返回空值/空值...扫描互联网后,我无法确定这是否是已知问题或是否有一个解决方法。这就是我访问配置设置的方式:

ConfigurationManager.ConnectionStrings["connName"].ConnectionString

如果在Windows机器(相同的git代码库)上调试了功能应用程序,则此方法工作正常

刘杰

在运行时2.x​​(.net核心)上运行的Azure函数v2不再支持ConfigurationManager。请参阅Azure团队在github上的回复

当我在Windows上调试v2函数时,System.Configuration.ConfigurationErrorsException抛出该错误。和v1一样,您仍然可以正常使用。

因此,如@mariocatch所说,请尝试改为读取环境变量。

供您参考的两个选项。

  1. 直接读取环境变量

    string connectionString = Environment.GetEnvironmentVariable("ConnectionStrings:connName");
    
  2. ExecutionContext context向您的函数方法参数添加并读取本地设置。

    [FunctionName("FunctionName")]
    public static void Run(...,ExecutionContext context)
    {
        var config = new ConfigurationBuilder()
            .SetBasePath(context.FunctionAppDirectory)
            .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
            .AddEnvironmentVariables()
            .Build();
        string connectionString = config.GetConnectionString("connName");
        .....
    }
    

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在本地运行Azure Function时无法读取local.settings.json文件

在VS 2017 Azure Function开发中从local.settings.json读取值

Azure函数将local.settings.json读取为对象

Azure 函数 - local.settings.json 与 launchSettings.json

VSCode无法在Mac上找到settings.json

使用MsTest运行单元测试时访问local.settings.json配置值

使用 local.settings.json 的 Azure 函数 cosmos db 输出

Python Azure Durable Functions:如何更改 local.settings.json 文件以读取 Azure Keyvault 的机密?

Azure Function EventHubTriggerAttribute不使用local.settings.json中的事件中心名称

无法读取在local.settings.json中定义的连接字符串

Azure Functions中local.settings.json中的值

Azure Functions Kubernetes 找不到 local.settings.json

Azure CI/CD 期间的 local.settings.json 转换

无法向 Azure 函数的 settings.json 添加对象

如何将VS中存储在local.settings.json中的SignalRConnectionString上传到Azure门户上的Azure函数

在Visual Studio 2017的local.settings.json本地开发中缺少AzureWebJobsStorage的值

Azure函数,使local.settings.json值优先于系统环境变量

如何将local.settings.json从Azure函数移植到.NET核心Web项目?

使用settings.json构建流星

无法使用Properties.Settings从app.config中读取

VScode settings.json

VS2017调试:无法访问COM对象的成员

参数化函数应用的 settings.json 以进行发布

settings.json文件中的Azure函数参数

基本Shopify-使用settings_scheme.json中的图像

使用settings.json代替mongodb集合有什么好处?

无法在github中使用VS2017进行拉或推

Unity在访问华为SDK时遇到问题,无法读取import agconnect-services.json

在调试测试时从local.setting.json读取值