Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core ignores ASPNET_ENV and Hosting:Environment

No matter when or where I set either ASPNET_ENV or Hosting:Environment the startup code will always enter

//This method is invoked when ASPNET_ENV is 'Production'
//The allowed values are Development,Staging and Production
public void ConfigureProduction(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
   loggerFactory.AddConsole(minLevel: LogLevel.Warning);

   Configure(app);
}

enter image description here

What I've tried so far

  • Set Hosting:Environment to Development in the project properties
  • Set ASPNET_ENV to Development in the project properties
  • Set Hosting:Environment to Development in launchSettings.json
  • Set ASPNET_ENV to Development in launchSettings.json
  • Set ASPNET_ENV to Development in code via Environment.SetEnvironmentVariable("ASPNET_ENV", "Development"); in the Startup method before the call to ConfigurationBuilder.GetEnvironmentVariables()

This is version 1.0.0-rc2-20143 by the way. Am I missing something here or is it just a bug?

like image 629
Thorsten Westheider Avatar asked Mar 13 '16 07:03

Thorsten Westheider


People also ask

What is hosting environment in ASP.NET Core?

ASP.NET Core apps configure and launch a host. The host is responsible for app startup and lifetime management. At a minimum, the host configures a server and a request processing pipeline. The host can also set up logging, dependency injection, and configuration.

Which environment values are Bydefault supported by .NET Core?

Built-In Environments in . When checking the ASP.NET core project template, you should see that the “ASPNETCORE_ENVIRONMENT” variable with the value “Development” is set by default. Those are three values that are used by convention: Development, Staging, and Production.

How do you check if current environment is development or not?

If you need to check whether the application is running in a particular environment, use env. IsEnvironment("environmentname") since it will correctly ignore case (instead of checking if env. EnvironmentName == "Development" for example).


Video Answer


1 Answers

The environment variable name has been changed to ASPNETCORE_ENVIRONMENT as part of the name change.

It was announced in this issue and change in this PR.

like image 141
Henk Mollema Avatar answered Oct 19 '22 08:10

Henk Mollema