Can I, how do I, supply a settings file to an Azure Function? Can I, how do I, supply a settings file to an Azure Function? azure azure

Can I, how do I, supply a settings file to an Azure Function?


When porting an application that uses a settings file to an Azure Function, is it necessary to remove reliance on the file?

Not necessary, we can still use the settings file required by the application. We only need to make sure the path of settings file is correct.

  1. Put appsettings.json under function project and set it to be copied to output/publish directory.

    set file property

  2. Add ExecutionContext context in Azure Function method signature, it's used to find current function app directory(where appsettings.json locates).

  3. Pass the valid path of appsettings.json in Azure Function to initialize XeroApiSettings.

    var xeroApiSettings = new XeroApiSettings(context.FunctionAppDirectory+"/appsettings.json");


This Jon Gallant's blog suggests that you need to add the optional parameter to the AddJsonFile as it does not exist when you deploy:

var config = new ConfigurationBuilder()    .SetBasePath(context.FunctionAppDirectory)    .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)    .AddEnvironmentVariables()    .Build();

Note that in Azure, this will refer to the 'appsettings.json' file