-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ASPNETCORE_Environment overrides cmd parameter #17963
Comments
I noticed a similar behavior with the ASPNETCORE_URLS variable: the value of the "Urls" section of the appsettings.json file always overrides the value of the environment variable. I stumbled across this problem working on a asp.net 3.1 core application with docker support enabled, where the environment variable was defined in the docker-compose.override.yml file. Please note that the precedence works exactly as expected with the other variables: environment always wins on the appsettings.json file. |
Any news on this? I've created the following extension method as a workaround, but it has not been battle-tested yet public static IWebHostBuilder FixEnvironmentParam(this IWebHostBuilder webBuilder, string[] args)
{
var configBuilder = new ConfigurationBuilder();
configBuilder.AddCommandLine(args);
var config = configBuilder.Build();
var env = config[HostDefaults.EnvironmentKey];
if (string.IsNullOrWhiteSpace(env))
{
return webBuilder;
}
return webBuilder.ConfigureAppConfiguration((host, _) => host.HostingEnvironment.EnvironmentName = env)
.UseEnvironment(env);
} |
We will take a look at this in the new year once folks are back from vacation |
Thanks for contacting us. |
In the documentation under Environment variable configuration provider there is the following sentence which probably explains the behavior reported by the OP.
|
#25273 seems related. It has to do with it not being obvious to what URL binding config overrides what. |
Looks like this behavior is documented here: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-6.0#default-builder-settings Admittedly, it could be a bit more clear about the fact that config loaded later in the order overrides earlier config. |
We should add a clear explanation in our docs of how the config is loaded from various places, in what order, and which things override others. |
Thanks for contacting us. |
I think one option here is to give
This would be a breaking change that would likely need to be announced as this would cause |
This should now be addressed in 7 since we did what @halter73 mentioned above. |
Reopening to consider changing the |
I moved this to preview 1 since it's a relatively small change that we should introduce early since it's breaking. |
Triage: this seems low priority and the current behavior is now documented better. Closing this issue. |
Describe the bug
We've noticed a very strange behavior of hosting environment setting. When using
ASPNETCORE_Environment="fromEnv"
environment variable and--Environment=fromCmd
command-line argument then for some reason the environment variable wins.This is very inconsistent given that:
ASPNETCORE_urls
vs--urls
- command-line argument wins 📗DOTNET_ENVIRONMENT
vs--Environment
- command-line argument wins 📗ASPNETCORE_ENVIRONMENT
vs--Environment
- environment variable wins 📙To Reproduce
I am able to reproduce it on a newly created ASP.NET Core 3.1 API project. The only small change I did is writing the current environment to the Console .
Further technical details
The text was updated successfully, but these errors were encountered: