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

问题描述 投票:1回答:1

所以我有这个简单的代码来从本地工作的自定义配置获取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中工作但它不再存在了吗?

任何想法如何解决这一问题?非常感谢!

c# azure azure-functions
1个回答
1
投票

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

appsettings

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

appsettings2

© www.soinside.com 2019 - 2024. All rights reserved.