You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unprefixed hosting environment variable (ENVIRONMENT) does not affect the value of IHostEnvironment.EnvironmentName.
Expected Behavior
Setting ENVIRONMENT=X should set IHostEnvironment.EnvironmentName with precedence over ASPNETCORE_ENVIRONMENT and DOTNET_ENVIRONMENT. In the same fashion in which it's applied to any other configuration value.
I was leaning toward assuming that the variable is ignored since it's overridden by launchSettings. But first, deleting launchSettings doesn't make a difference in the problem (only changing Development to Production). And for other variables unprefixed variables take precedence over variables prefixed with ASPNETCORE_
The text was updated successfully, but these errors were encountered:
I expected it to work because it would be consistent with the way all other environment variables are read.
This variable seemed like a logical choice for experimenting with environment variables and ASP.NET Core and (at least for me) experimenting brought confusion as to whether unprefixed variables are used in general. While I can certainly use a prefixed variable, I wanted to at least figure out if this decision about the ENVIRONMENT variable was intentional.
It was intentional. You can set and read any environment variable via IConfiguration, but IHostingEnvironment is only impacted by ASPNETCORE_ENVIRONMENT or DOTNET_ENVIRONMENT intentionally.
Is there an existing issue for this?
Describe the bug
Unprefixed hosting environment variable (
ENVIRONMENT
) does not affect the value ofIHostEnvironment.EnvironmentName
.Expected Behavior
Setting
ENVIRONMENT=X
should setIHostEnvironment.EnvironmentName
with precedence overASPNETCORE_ENVIRONMENT
andDOTNET_ENVIRONMENT
. In the same fashion in which it's applied to any other configuration value.Steps To Reproduce
repo: https://github.com/astorDev/hosting-env-unprefixed-variable-repro
Simple steps:
Hosting environment:
Exceptions (if any)
No response
.NET Version
8.0.101
Anything else?
I was leaning toward assuming that the variable is ignored since it's overridden by
launchSettings
. But first, deletinglaunchSettings
doesn't make a difference in the problem (only changing Development to Production). And for other variables unprefixed variables take precedence over variables prefixed withASPNETCORE_
The text was updated successfully, but these errors were encountered: