在调试测试时从local.setting.json读取值 [英] Read values from local.setting.json while debugging test

查看:340
本文介绍了在调试测试时从local.setting.json读取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行或调试测试时,我似乎无法通过azure函数从此文件中读取任何内容,但是在本地调试整个应用程序时,它可以正常工作.任何人都可以解释为什么吗?

i don't seem to be able to read anything from this file in an azure functions when running or debugging a test, however it works fine when debugging the whole application locally.. can anyone explain why at all ?

{
  "IsEncrypted": false,
  "Values": {
    "xyz": 123
  }
}

var res = ConfigurationManager.AppSettings.Get("xyz");

ty ..

我可疑的是,这是由于从另一个项目(测试项目)启动了调试",而local.settings.json并没有与正在测试的项目捆绑在一起吗?

my suspicious is that it is due to the 'debug' being initiated from another project (Test project), and the local.settings.json does not get bundled up with the project being tested ?

推荐答案

您的怀疑已经存在.实际上,只有Azure Functions运行时主机知道从该文件读取设置并将它们合并到整个AppSettings中.在测试项目中运行时,不涉及Azure Functions运行时主机,因此您无法访问它们.

Your suspicion is spot on. Only the Azure Functions Runtime Host actually knows to read settings from that file and merge them into the overall AppSettings. When you run in a test project, the Azure Functions Runtime Host is not involved and therefore you don't get access to them.

解决此问题的最简单方法是将所有相同的设置键/值反映到标准<appSettings>部分下测试项目的app.config文件中.

The simplest way to solve this would be to reflect all the same setting keys/values into your test project's app.config file under the standard <appSettings> section.

这篇关于在调试测试时从local.setting.json读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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