I’m trying to migrate some functionality of a legacy .NET Framework over to Azure Function Apps V4 using dotnet-isolated. I can trigger the application, however the app settings and connection strings defined in the Azure Portal are not available through ConfigurationManager
. Other parts of this application are hosted on App Services and ConfigurationManager
works fine there.
There’s a lot of information available about IConfiguration
and local.settings.json
, however that’s not what I can use. There’s a lot of code depending on ConfigurationManager.AppSettings
and ConfigurationManager.ConnectionStrings
, which need to keep working as-is. One example is EF6, but also other custom code.
I’ve defined the app settings and connection strings in the Azure Portal. I can see these as environment variables in the Kudu "Environment" view, like this:
APPSETTING_my_setting="myvalue"
SQLAZURECONNSTR_my_connection_string="foo=bar"
I somehow would’ve expected for this to "just work", but it doesn’t. Am I holding it wrong, or what can I do to convince ConfigurationManager
to use these settings?
2
Answers
The Values which are set in the
local.settings.josn
are available as Environment Variables.My
.csproj
file:We can read either by using the
EnvironmentVariable
or from theIConfiguration
.Using EnvironmentVariable:
My
Function1.cs
file:Using IConfiguration:
OR
If set under ConnectionString
then read it as,
Output:
ConfigurationManager
has never been driven by environment variables, and supports the.config
XML configuration pattern. You still have that in App Service, in that it has a filesystem where those files can be placed in the relative location that (ASP.)NET expects, but it has no relationship to the App Service configuration collection. I suppose if you are familiar with IIS on-premises you might imagine that the configuration UI would be a view onto this XML configuration file, but that isn’t the case anymore, App Service configuration is distinct and is expressed to the application as environment variables.