diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs index b38f997c..50be2280 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs @@ -63,7 +63,6 @@ public static void Initialize(this IHostingEnvironment hostingEnvironment, strin hostingEnvironment.EnvironmentName = options.Environment ?? - Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? hostingEnvironment.EnvironmentName; } } diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs index 88cd1c76..ef8589c5 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs @@ -45,6 +45,9 @@ public WebHostBuilder() _hostingEnvironment = new HostingEnvironment(); _configureServicesDelegates = new List>(); _configureLoggingDelegates = new List>(); + + // This may end up storing null, but that's indistinguishable from not adding it. + UseSetting(WebHostDefaults.EnvironmentKey, Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")); } ///