Read values from local.setting.json while debugging test(调试测试时从 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 suspicion 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.
解决这个问题的最简单方法是将所有相同的设置键/值反映到标准<下的测试项目的 部分.app.config文件中.appSettings>
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 读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:调试测试时从 local.setting.json 读取值
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
