繁体   English   中英

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

[英]Finding custom .config file in azure function?

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

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 门户中配置这些:

应用程序设置

此处的所有设置都会覆盖您在 web/app.config 或 local.settings.json 中的任何内容:

appsettings2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM