c# - 在azure函数中查找自定义.config文件?

标签 c# azure azure-functions

所以我有这个简单的代码来从本地工作的自定义配置中获取应用程序设置:

ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();

configFileMap.ExeConfigFilename = "My.config"; // This works locally but not on azure I think
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);

AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings");
var test = section.Settings["test"].Value; // throws nullref

现在,我在另一个项目中拥有“My.config”,并设置为“始终复制”到构建目录,并且在使用 Azure-cli (localhost) 进行调试时它可以完美运行。事实上,我认为这以前可以在 Azure 中运行,但现在不行了?

有什么想法可以解决这个问题吗?非常感谢!

最佳答案

您需要使用应用程序设置在 Azure 门户中配置这些:

appsettings

此处的所有设置都将覆盖您在 web/app.config 或 local.settings.json 中的所有设置:

appsettings2

关于c# - 在azure函数中查找自定义.config文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49071520/

相关文章:

c# - 如何使用多个条件和 LINQ 过滤列表中的数据?

c# - MSBuild失败: IsOsPlatform not found

azure - 如何在 Azure 中将 xml 数据转换为 csv/excel/table

Azure Function on Time Trigger 未触发

azure - 通过 azure/docker-login 使用 secret

azure - 在 VSCode 中调试 Azure Function (Python) 和 RuntimeError : Can't listen for client connections: [WinError 10048]

c# - fxcop 是提高代码质量的有值(value)/有效的工具吗?

c# - 将矩形添加到pdfpcell itextsharp中

c# - 函数参数中的列表文本框

azure cli 添加应用程序注册范围