Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Rename environment variables to ASPNETCORE_. #640

Merged
merged 1 commit into from
Mar 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public static class WebHostDefaults
public static readonly string ApplicationBaseKey = "applicationBase";

public static readonly string HostingJsonFile = "hosting.json";
public static readonly string EnvironmentVariablesPrefix = "ASPNET_";
public static readonly string EnvironmentVariablesPrefix = "ASPNETCORE_";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static IConfiguration GetDefault(string[] args)
};

// Setup the default locations for finding hosting configuration options
// hosting.json, ASPNET_ prefixed env variables and command line arguments
// hosting.json, ASPNETCORE_ prefixed env variables and command line arguments
var configBuilder = new ConfigurationBuilder()
.AddInMemoryCollection(defaultSettings)
.AddJsonFile(WebHostDefaults.HostingJsonFile, optional: true)
Expand Down
4 changes: 1 addition & 3 deletions src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace Microsoft.AspNetCore.Hosting.Internal
{
public class WebHostOptions
{
private const string OldEnvironmentKey = "ENV";

public WebHostOptions()
{
}
Expand All @@ -24,7 +22,7 @@ public WebHostOptions(IConfiguration configuration)
Application = configuration[WebHostDefaults.ApplicationKey];
DetailedErrors = ParseBool(configuration, WebHostDefaults.DetailedErrorsKey);
CaptureStartupErrors = ParseBool(configuration, WebHostDefaults.CaptureStartupErrorsKey);
Environment = configuration[WebHostDefaults.EnvironmentKey] ?? configuration[OldEnvironmentKey];
Environment = configuration[WebHostDefaults.EnvironmentKey];
ServerFactoryLocation = configuration[WebHostDefaults.ServerKey];
WebRoot = configuration[WebHostDefaults.WebRootKey];
ApplicationBasePath = configuration[WebHostDefaults.ApplicationBaseKey];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public DeploymentParameters(
ApplicationPath = applicationPath;
ServerType = serverType;
RuntimeFlavor = runtimeFlavor;
EnvironmentVariables.Add(new KeyValuePair<string, string>("ASPNET_DETAILEDERRORS", "true"));
EnvironmentVariables.Add(new KeyValuePair<string, string>("ASPNETCORE_DETAILEDERRORS", "true"));
}

public ServerType ServerType { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected void AddEnvironmentVariablesToProcess(ProcessStartInfo startInfo)
startInfo.Environment;
#endif

SetEnvironmentVariable(environment, "ASPNET_ENV", DeploymentParameters.EnvironmentName);
SetEnvironmentVariable(environment, "ASPNETCORE_ENVIRONMENT", DeploymentParameters.EnvironmentName);

foreach (var environmentVariable in DeploymentParameters.EnvironmentVariables)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void ReadsParametersCorrectly()
[Fact]
public void ReadsOldEnvKey()
{
var parameters = new Dictionary<string, string>() { { "ENV", "Development" } };
var parameters = new Dictionary<string, string>() { { "ENVIRONMENT", "Development" } };
var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build());

Assert.Equal("Development", config.Environment);
Expand Down
4 changes: 1 addition & 3 deletions test/Microsoft.AspNetCore.Hosting.Tests/WebHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ public void EnvDefaultsToConfigValueIfSpecifiedWithOldKey()
{
var vals = new Dictionary<string, string>
{
// Old key is actualy ASPNET_ENV but WebHostConfiguration expects environment
// variable names stripped from ASPNET_ prefix so using just ENV here
{ "ENV", "Staging" }
{ "environment", "Staging" }
};

var builder = new ConfigurationBuilder()
Expand Down