ASPNETCORE_ENVIRONMENT
when ConfigureWebHostDefaults is called. The default ASP.NET Core web app templates call ConfigureWebHostDefaults
. The ASPNETCORE_ENVIRONMENT
value overrides DOTNET_ENVIRONMENT
.IHostEnvironment.EnvironmentName
can be set to any value, but the following values are provided by the framework:ASPNETCORE_ENVIRONMENT
to Development
on the local machine.DOTNET_ENVIRONMENT
and ASPNETCORE_ENVIRONMENT
have not been set.ASPNETCORE_ENVIRONMENT
is set to Development
.ASPNETCORE_ENVIRONMENT
is set to Staging
, Production
, or Staging_2
.Startup.Configure
. This approach is useful when the app only requires adjusting Startup.Configure
for a few environments with minimal code differences per environment.IWebHostEnvironment.EnvironmentName
.dotnet new
:IIS Express
: The default profile used when launching the app from Visual Studio. The 'commandName'
key has the value 'IISExpress'
, therefore, IISExpress is the web server. You can set the launch profile to the project or any other profile included. For example, in the image below, selecting the project name launches the Kestrel web server.EnvironmentsSample
: The profile name is the project name. This profile is used by default when launching the app with dotnet run
. The 'commandName'
key has the value 'Project'
, therefore, the Kestrel web server is launched.commandName
can specify the web server to launch. commandName
can be any one of the following:IISExpress
: Launches IIS Express.IIS
: No web server launched. IIS is expected to be available.Project
: Launches Kestrel.dotnet run --launch-profile <Profile Name>
.Production
, which disables most debugging features. The method for setting the environment depends on the operating system.IWebHostEnvironment.EnvironmentName
.ASPNETCORE_ENVIRONMENT
for the Name. For Value, provide the environment (for example, Staging
).ASPNETCORE_ENVIRONMENT
for the current session when the app is started using dotnet run, the following commands are used:ASPNETCORE_ENVIRONMENT
only for processes launched from that command window.ASPNETCORE_ENVIRONMENT
value:setx
command or open an administrative PowerShell command prompt and use [Environment]::SetEnvironmentVariable
:/M
switch indicates to set the environment variable at the system level. If the /M
switch isn't used, the environment variable is set for the user account.Machine
option value indicates to set the environment variable at the system level. If the option value is changed to User
, the environment variable is set for the user account.ASPNETCORE_ENVIRONMENT
environment variable is set globally, it takes effect for dotnet run
in any command window opened after the value is set. Environment values in launchSettings.json override values set in the system environment.ASPNETCORE_ENVIRONMENT
environment variable with web.config, see the Setting environment variables section of ASP.NET Core Module.<EnvironmentName>
property in the publish profile (.pubxml) or project file. This approach sets the environment in web.config when the project is published:ASPNETCORE_ENVIRONMENT
environment variable for an app running in an isolated Application Pool (supported on IIS 10.0 or later), see the AppCmd.exe command section of the Environment Variables <environmentVariables> topic. When the ASPNETCORE_ENVIRONMENT
environment variable is set for an app pool, its value overrides a setting at the system level.ASPNETCORE_ENVIRONMENT
environment variable, use any one of the following approaches to have the new value picked up by apps:net stop was /y
followed by net start w3svc
from a command prompt.export
prior to running the app:export
command at a command prompt for session-based variable settings and bash_profile file for machine-level environment settings.Startup
constructor. This approach is useful when the app requires configuring Startup
for only a few environments with minimal code differences per environment._env
field._env
is used in ConfigureServices
and Configure
to apply startup configuration based on the app's environment.Startup
classes for different environments. The appropriate Startup
class is selected at runtime. The class whose name suffix matches the current environment is prioritized. If a matching Startup{EnvironmentName}
class isn't found, the Startup
class is used. This approach is useful when the app requires configuring startup for several environments with many code differences per environment. Typical apps will not need this approach.Startup
classes, create a Startup{EnvironmentName}
classes and a fallback Startup
class:Configure<EnvironmentName>
and Configure<EnvironmentName>Services
. This approach is useful when the app requires configuring startup for several environments with many code differences per environment:ASPNETCORE_ENVIRONMENT
at app startup and stores the value in IHostingEnvironment.EnvironmentName. ASPNETCORE_ENVIRONMENT
can be set to any value, but three values are provided by the framework:ASPNETCORE_ENVIRONMENT
is set to Development
.ASPNETCORE_ENVIRONMENT
is set one of the following:Staging
Production
Staging_2
IHostingEnvironment.EnvironmentName
to include or exclude markup in the element:applicationUrl
property in launchSettings.json can specify a list of server URLs. Use a semicolon between the URLs in the list:'commandName': 'Project'
is used. The value of commandName
specifies the web server to launch. commandName
can be any one of the following:IISExpress
IIS
Project
(which launches Kestrel)environmentVariables
settings in launchSettings.json override environment variables.Development
:dotnet run
in the same way as Properties/launchSettings.json. When launching an app in development that doesn't have a launchSettings.json file, either set the environment with an environment variable or a command-line argument to the dotnet run
command.Production
, which disables most debugging features. The method for setting the environment depends on the operating system.ASPNETCORE_ENVIRONMENT
for the Name. For Value, provide the environment (for example, Staging
).ASPNETCORE_ENVIRONMENT
for the current session when the app is started using dotnet run, the following commands are used:ASPNETCORE_ENVIRONMENT
setting reverts to the default setting or machine value.ASPNETCORE_ENVIRONMENT
value:setx
command or open an administrative PowerShell command prompt and use [Environment]::SetEnvironmentVariable
:/M
switch indicates to set the environment variable at the system level. If the /M
switch isn't used, the environment variable is set for the user account.Machine
option value indicates to set the environment variable at the system level. If the option value is changed to User
, the environment variable is set for the user account.ASPNETCORE_ENVIRONMENT
environment variable is set globally, it takes effect for dotnet run
in any command window opened after the value is set.ASPNETCORE_ENVIRONMENT
environment variable with web.config, see the Setting environment variables section of ASP.NET Core Module.<EnvironmentName>
property in the publish profile (.pubxml) or project file. This approach sets the environment in web.config when the project is published:ASPNETCORE_ENVIRONMENT
environment variable for an app running in an isolated Application Pool (supported on IIS 10.0 or later), see the AppCmd.exe command section of the Environment Variables <environmentVariables> topic. When the ASPNETCORE_ENVIRONMENT
environment variable is set for an app pool, its value overrides a setting at the system level.ASPNETCORE_ENVIRONMENT
environment variable, use any one of the following approaches to have the new value picked up by apps:net stop was /y
followed by net start w3svc
from a command prompt.export
prior to running the app:export
command at a command prompt for session-based variable settings and bash_profile file for machine-level environment settings.Startup.Configure
. This approach is useful when the app only requires configuring Startup.Configure
for only a few environments with minimal code differences per environment.Startup
constructor and assign the service to a field for use throughout the Startup
class. This approach is useful when the app requires configuring startup for only a few environments with minimal code differences per environment._env
field._env
is used in ConfigureServices
and Configure
to apply startup configuration based on the app's environment.Startup
classes for different environments (for example, StartupDevelopment
). The appropriate Startup
class is selected at runtime. The class whose name suffix matches the current environment is prioritized. If a matching Startup{EnvironmentName}
class isn't found, the Startup
class is used. This approach is useful when the app requires configuring startup for several environments with many code differences per environment.Startup
classes, create a Startup{EnvironmentName}
class for each environment in use and a fallback Startup
class:Configure<EnvironmentName>
and Configure<EnvironmentName>Services
. This approach is useful when the app requires configuring startup for several environments with many code differences per environment.Directive | Meaning |
---|---|
vbc | Visual Basic compiler |
csc | C# compiler |
-r: | References an external assembly (EXE or DLL) |
-d: | Defines a conditional compilation symbol |
vbc /?
(for Visual Basic) or csc /?
(for C#) at the command prompt. For more information, see Building from the Command Line (C#) or Invoking the Command-Line Compiler (Visual Basic).Language | Statement | Result |
---|---|---|
Visual Basic | #CONST TRACE = true | Enables tracing |
#CONST TRACE = false | Disables tracing | |
#CONST DEBUG = true | Enables debugging | |
#CONST DEBUG = false | Disables debugging | |
C# | #define TRACE | Enables tracing |
#undef TRACE | Disables tracing | |
#define DEBUG | Enables debugging | |
#undef DEBUG | Disables debugging |