Skip to content

Commit

Permalink
Tools: Default DOTNET_ENVIRONMENT to Development
Browse files Browse the repository at this point in the history
Fixes #19903
  • Loading branch information
bricelam committed Jul 27, 2020
1 parent 9046e12 commit 42682b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/EFCore.Design/Design/Internal/AppServiceProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,19 @@ private IServiceProvider CreateFromHosting(string[] args)
return null;
}

// TODO: Remove when dotnet/cli#6617 is fixed
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
if (environment == null)
var aspnetCoreEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var dotnetEnvironment = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT");
var environment = aspnetCoreEnvironment
?? dotnetEnvironment
?? "Development";
if (aspnetCoreEnvironment == null)
{
environment = "Development";
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", environment);
}
if (dotnetEnvironment == null)
{
Environment.SetEnvironmentVariable("DOTNET_ENVIRONMENT", environment);
}

_reporter.WriteVerbose(DesignStrings.UsingEnvironment(environment));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void Create_works()
MockAssembly.Create(typeof(Program)));

Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", null);
Environment.SetEnvironmentVariable("DOTNET_ENVIRONMENT", null);
var services = factory.Create(new[] { "arg1" });

Assert.NotNull(services.GetRequiredService<TestService>());
Expand All @@ -29,6 +30,7 @@ private class Program
public static TestWebHost BuildWebHost(string[] args)
{
Assert.Equal("Development", Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"));
Assert.Equal("Development", Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT"));
Assert.Equal(args, new[] { "arg1" });

return new TestWebHost(
Expand Down

0 comments on commit 42682b5

Please sign in to comment.