Turbo
Turbo

Reputation: 2561

AZURE_FUNCTIONS_ENVIRONMENT vs ASPNETCORE_ENVIRONMENT

In azure functions (v2, c#), there are two environment variables that can be potentially used to identify the name of the current 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:

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

Answers (2)

Turbo
Turbo

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 the AZURE_FUNCTIONS_ENVIRONMENT app setting (as EnvironmentSettingNames.EnvironmentNameKey) and passes it to the IWebHostBuilder. Using only ASPNETCORE_ENVIRONMENT can lead to desired behavior changes and telemetry being missed.

Upvotes: 19

alsami
alsami

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

Related Questions