Hi
I've read your post https://www.forestbrook.net/docs/azure/functionwithkeyvaultanddi.html and highly appreciated it! Thank you!!!
But I've found an issue/problem with how Azure Functions work, and the way you add the configuration providers for appsettings.json files.
Nothing wrong really, but since the appsettings JSON configurations providers (configurationsource) are added after the ones provided by Azure Functions, they will override any value you specify in the application settings in the Azure portal for your Azure function.
You can also test it locally and see that, for any setting that has value both in appsettings.json and in local.settings.json, the last added providers (appsettings.json) wins.
If we compare that to appsettings.json and application settings on an Azure App Service, it is the other way around - the application settings "overrides" any setting in appsettings.json.
To solve it properly, we would need to change code in the Azure Functions framework, but I've come up with a workaround, which needs bo be invoked after adding the appsettings.json fileproviders, and before adding the KeyVault provider.
private static void PrioritizeEnvironmentVariables(IFunctionsConfigurationBuilder builder)
{
var commandlineProvider = builder.ConfigurationBuilder.Sources.LastOrDefault(x => x is Microsoft.Extensions.Configuration.EnvironmentVariables.EnvironmentVariablesConfigurationSource);
if (commandlineProvider != null)
{
builder.ConfigurationBuilder.Sources.Remove(commandlineProvider);
builder.ConfigurationBuilder.Sources.Add(commandlineProvider);
}
}
I hope it was OK to add this feedback as an issue. I could not easily find another way to contact you.
Best regards
Marcus Nilsson