Reputation: 2561
In azure functions (v2, c#), there are two environment variables that can be potentially used to identify the name of the current environment.
AZURE_FUNCTIONS_ENVIRONMENT
ASPNETCORE_ENVIRONMENT
I am planning to use AZURE_FUNCTIONS_ENVIRONMENT
, and I am wondering if there are reasons to choose one over another?
In terms of behavior of the two, this is what I discovered:
AZURE_FUNCTIONS_ENVIRONMENT
is set to Development
locally by the functions host/runtime. It is not automatically set in azure to Production
. One can set this in App Settings in azure.ASPNETCORE_ENVIRONMENT
is not set by the functions host/runtime either locally or in Azure.I have also raised a github issue about this a couple of weeks ago, but got no response. I am hoping I might get an answer here.
Upvotes: 16
Views: 12988
Reputation: 2561
Adding the official answer from github issue here for everyone's benefit:
You'll want to use
AZURE_FUNCTIONS_ENVIRONMENT
. The Functions runtime that powers a Function app on Azure is the WebHost project in this repo. As the host is initializing, it looks for theAZURE_FUNCTIONS_ENVIRONMENT
app setting (asEnvironmentSettingNames.EnvironmentNameKey
) and passes it to the IWebHostBuilder. Using onlyASPNETCORE_ENVIRONMENT
can lead to desired behavior changes and telemetry being missed.
Upvotes: 19
Reputation: 9825
ASPNETCORE_ENVIRONMENT
is the default environment-variable to determine the environment for IHostingEnvironment
. IHostingEnvironment
has current two implementations. One can be found here and is only supposed to be used internally. The other can be found here.
The exact idea on why there is AZURE_FUNCTIONS_ENVIRONMENT
I cannot tell. I would suggest you to stick to IHostingEnvironment
for ASP.NET Core applications. The version of IHostingEnvironment
will be replaced with IWebHostEnvironment
in the future. With the release of 3.0 they will continue to support both until the remove it. It will be marked as obsolete.
In your functions you can always set custom variables and just access them via Environment.GetEnvironmentVariable("MY-VAR")
.
Upvotes: 1