-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
UseEnvironment overwritten by ConfigureWebHostDefaults #47050
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue DetailsDescribe the bugUseEnvironment is not picked up in ASP.NET Core 3.1. I'm using It worked great in v2.2, but I've recently migrated to 3.1 and it's not being used anymore. To Reproduce
Host.CreateDefaultBuilder(args)
.UseEnvironment(EnvironmentName)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.Build(); From what I understand, it cannot be set later as it won't be picked up in the Startup class then. WorkaroundCurrently I'm doing the following instead: Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
// This overrides the default configuration
webBuilder.UseSetting(WebHostDefaults.EnvironmentKey, EnvironmentName);
webBuilder.UseStartup<Startup>();
})
.Build(); imho using the explicit I know that this has been discussed in dotnet/aspnetcore#18499. Just saying "wont fix" leads to hours wasted trying to figure out why it isn't working. At least throw an exception
|
Notes from dotnet/aspnetcore#18499:
|
Hey, @maryamariyan and @eerhardt - do you mind if I take this one? |
Go ahead! Thanks. |
Hi @jgauffin, I'm thinking that we should update some of the docs around the API usage here, perhaps update the If I'm understanding this correctly, isn't another workaround to simply change the order of the fluent-calls? Instead of: Host.CreateDefaultBuilder(args)
.UseEnvironment(EnvironmentName)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.Build(); Do this: Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.UseEnvironment(EnvironmentName)
.Build(); Move the call after the defaults are configured: Host.CreateDefaultBuilder(args)
- .UseEnvironment(EnvironmentName)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
+ .UseEnvironment(EnvironmentName)
.Build(); Placing the /cc @davidfowl @eerhardt |
It was a while ago that I tried, but think that I tried to move it after and that didn't help. Either way, please throw exceptions if the configuration API is used in a way that doesn't work. |
Hi @jgauffin - this does work. I have verified it. The order matters, you need to chain the fluent
This is common with ASP.NET Core app, as the template uses the .NET runtime Correctly ordered callsConsole app without ASP.NET Core Incorrectly ordered calls
I believe that we do |
Describe the bug
UseEnvironment is not picked up in ASP.NET Core 3.1.
I'm using
UseEnvironment
to toggle between configurations when running in Visual Studio (between on-premise and cloud versions of my service).It worked great in v2.2, but I've recently migrated to 3.1 and it's not being used anymore.
To Reproduce
UseEnvironment
:From what I understand, it cannot be set later as it won't be picked up in the Startup class then.
Workaround
Currently I'm doing the following instead:
imho using the explicit
UseEnvironment
method should always override the default implementation (ASPNETCORE_Environment) as it's not part of the default configuration, and thus means that the dev really wants to override the default config.I know that this has been discussed in dotnet/aspnetcore#18499. Just saying "wont fix" leads to hours wasted trying to figure out why it isn't working. At least throw an exception
NotSupportedException
when the API is used until you can fix or remove it.The text was updated successfully, but these errors were encountered: