liveBook · Manning

ASP.NET Core environment

As explained in ASP.NET Core in Action, 3e

ASPNETCORE_ENVIRONMENT is an environment variable that identifies the current ASP.NET Core hosting environment.

ASP.NET Core uses ASPNETCORE_ENVIRONMENT to identify the hosting environment for an application. WebApplicationBuilder reads the variable and exposes the result through WebApplicationBuilder.Environment and IHostEnvironment.EnvironmentName. section 10.4.1

Use the environment name to select behavior and configuration appropriate to where the application runs.

  • Prefer Development, Staging, and Production; other values are allowed, but these have built-in helper methods. section 10.4.1
  • Check environments with IsDevelopment(), IsStaging(), IsProduction(), or IsEnvironment(string), which perform case-insensitive comparisons. section 10.4.1
  • If ASPNETCORE_ENVIRONMENT is unset, ASP.NET Core assumes Production; locally, launchSettings.json can scope the variable to a project. section 10.5
  • DOTNET_ENVIRONMENT is also supported, but ASPNETCORE_ENVIRONMENT takes precedence when both variables are set. section 10.4.1

Selecting a local environment

Set ASPNETCORE_ENVIRONMENT to Development while running locally. The application then exposes Development as EnvironmentName, allowing environment-specific files such as appsettings.Development.json to be selected. section 10.4.1 section 10.5

IHostEnvironment also identifies the application’s content root, where configuration files are found. The web root is separate: WebRootPath, typically wwwroot, identifies browser-accessible static files. section 10.4.1

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines variable loading, precedence, defaults, helper checks, and environment-specific files, but does not detail broader application customization.
Examples
Uses Development, Staging, Production, launchSettings.json, and appsettings.Production.json as concrete environment examples.
What you can do after
Operate/configure an application by setting its hosting environment and selecting matching configuration files.
How it connects
Connects ASPNETCORE_ENVIRONMENT with WebApplicationBuilder, IHostEnvironment, launchSettings.json, and appsettings environment-specific files.

Also explained in

Compare how 2 books explain ASP.NET Core environment →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.