From e6bddd4131e72ae268b301d96b201bd986812289 Mon Sep 17 00:00:00 2001 From: Chris R Date: Thu, 28 Apr 2016 15:11:43 -0700 Subject: [PATCH 1/2] Prepopulate the environment rather than fall back to it. --- .../Internal/HostingEnvironmentExtensions.cs | 1 - src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs index b38f997cac..50be22800b 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/HostingEnvironmentExtensions.cs @@ -63,7 +63,6 @@ namespace Microsoft.AspNetCore.Hosting.Internal 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 88cd1c76fb..ef8589c572 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs @@ -45,6 +45,9 @@ namespace Microsoft.AspNetCore.Hosting _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")); } /// From 642cdc043706e95e2ffaf033c021ff2e0ac4b55e Mon Sep 17 00:00:00 2001 From: Chris R Date: Tue, 3 May 2016 09:02:44 -0700 Subject: [PATCH 2/2] #738 Support legacy environment keys --- src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs index ef8589c572..f4146effca 100644 --- a/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs +++ b/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs @@ -47,7 +47,19 @@ namespace Microsoft.AspNetCore.Hosting _configureLoggingDelegates = new List>(); // This may end up storing null, but that's indistinguishable from not adding it. - UseSetting(WebHostDefaults.EnvironmentKey, Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")); + UseSetting(WebHostDefaults.EnvironmentKey, Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") + // Legacy keys, never remove these. + ?? Environment.GetEnvironmentVariable("Hosting:Environment") + ?? Environment.GetEnvironmentVariable("ASPNET_ENV")); + + if (Environment.GetEnvironmentVariable("Hosting:Environment") != null) + { + Console.WriteLine("The environment variable 'Hosting:Environment' is obsolete and has been replaced with 'ASPNETCORE_ENVIRONMENT'"); + } + if (Environment.GetEnvironmentVariable("ASPNET_ENV") != null) + { + Console.WriteLine("The environment variable 'ASPNET_ENV' is obsolete and has been replaced with 'ASPNETCORE_ENVIRONMENT'"); + } } ///