Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Functions - using appsettings.json

Tags:

Is it possible to use an appsettings.json file in Azure Functions?

There is documentation for environment variables here..

https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#environment-variables

..however we use Octopus for deployments and would really like to have appsettings version controlled.

We have tried using

{   "frameworks": {     "net46": {       "dependencies": {         "Microsoft.Extensions.Configuration": "1.0.0",         "Microsoft.Extensions.Configuration.Json": "1.0.0"       }     }   } } 

but constantly get

2016-11-23T15:27:03.811 (12,16): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0

Even being able to supply/update environment variables via Octopus would be sufficient for our needs.

Please advise.

like image 972
Nosmadas Avatar asked Nov 23 '16 15:11

Nosmadas


People also ask

Does Azure app settings override Appsettings json?

For ASP.NET and ASP.NET Core developers, setting app settings in App Service are like setting them in <appSettings> in Web. config or appsettings. json, but the values in App Service override the ones in Web.

What is AzureWebJobsStorage used for?

AzureWebJobsStorage. The Azure Functions runtime uses this storage account connection string for normal operation. Some uses of this storage account include key management, timer trigger management, and Event Hubs checkpoints. The storage account must be a general-purpose one that supports blobs, queues, and tables.

How do I get Azure function connection string?

Get connection informationSign in to the Azure portal. Select SQL Databases from the left-hand menu, and select your database on the SQL databases page. Select Connection strings under Settings and copy the complete ADO.NET connection string.


1 Answers

For your needs the answer is YES! Azure Functions can use appsettings.json for your configurations. But there are some ordering sequence that Azure will do when a Function is requested.

1º) Azure will look for that KEYS that you used on .GetEnvironmentVariables("[KEY]") method, through Keys that were configured on Application Settings blade in Azure Functions settings

2º) If Azure wasn't able to find out that configurations through Application Settings keys, then Azure will try looking for after appsettings.json file into your root folder of the Function that you working on.

3º) Finally, if Azure wasn't able to find out this keys either on Application Settings neither on appsettings.json file, then Azure will do the last attempt to find out web.config for looking for into this file appsettings section keys.

For your appreciation, you'll able to find out these configurations by the sample on my github repo: here and here

I hope that these information help you.

like image 174
Jose Roberto Araujo Avatar answered Sep 29 '22 21:09

Jose Roberto Araujo