Use the .Net core configuration management style, contained in package Microsoft.Extensions.Configuration
. The local.settings.json
file isn't published to Azure, and instead, Azure will obtain settings from the Application Settings associated with the Function.
In your function add a parameter of type Microsoft.Azure.WebJobs.ExecutionContext
context, where you can then build an IConfigurationRoot
provider: Example :
[FunctionName("Stackoverflow")]
public static async Task Run([TimerTrigger("0 */15 * * * *")]TimerInfo myTimer,
TraceWriter log, ExecutionContext context,
CancellationToken ctx)
{
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
// This abstracts away the .json and app settings duality
var myValue = config["MyKey"];
}
Once when its deployed to Azure, you can change the values of the settings on the function Application Settings.
