我在Azure Functions项目中有2个设置文件。
1) local.settings.json
2) appsettings.json
在Startup.cs中,我将两者组合成一个单一的配置,并且在本地调试的代码中一切都很好。
Config = new ConfigurationBuilder()
.SetBasePath(currentDirectory)
.AddConfiguration(configuration)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
Appsetings。Json包含嵌套的值。如:
{
"Test":
{
"abc":"def"
}
}
我正在使用Azure DevOps中的发布管道部署我的代码到一个功能应用程序。
我正在使用">Azure应用程序服务设置";任务,将最终部署中的值替换为Function App。
所以上面提到的Release任务中的值是,
[
{ "name": "FUNCTIONS_WORKER_RUNTIME", "value": "dotnet", "slotSetting": false },//from local.settings.json
{ "name": "Test__abc", "value": "def", "slotSetting": false },//from appsettings.json
]
问题:
代码部署没有任何问题,并且local.setting.json值传递正常。但问题在于应用程序。json值。这被添加到Azure Portal的Configuration选项卡中,但它似乎没有被应用程序使用。应用程序出错,因为该值为空。
如何通过发布任务将appsetting值传递给Azure function ?
应用程序开始工作后,我在启动。addenvironmentvariables()。
Config = new ConfigurationBuilder()
.SetBasePath(currentDirectory)
.AddConfiguration(configuration)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();