An ASP.NET Core environment identifies the phase in which an application is running. Common values are Development for debugging, Staging for testing, and Production for end users. Set the runtime environment with DOTNET_ENVIRONMENT or ASPNETCORE_ENVIRONMENT in the application's execution context. section 2.4.2
For a local web API, set ASPNETCORE_ENVIRONMENT to Development under each launch profile's environmentVariables entry in launchSettings.json. This lets the IIS Express and Kestrel profiles start the application in the intended environment. section 2.4.1
The environment also selects configuration values. appsettings.json supplies settings shared across environments; appsettings.Development.json adds development-only settings and replaces matching values from the shared file because it is read afterward. section 2.4.2
Check environment-dependent behavior
In Program.cs, app.Environment.IsDevelopment() can enable Swagger UI and DeveloperExceptionPageMiddleware for Development while the other branch uses ExceptionHandlerMiddleware. Add a test endpoint that throws an exception, start the API, and visit /error/test: Development displays the developer exception page. Change ASPNETCORE_ENVIRONMENT to Production to test the exception handler instead. A separate UseDeveloperExceptionPage configuration key can control that choice without changing the environment. section 2.4.3 section 2.4.2
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
if (app.Configuration.GetValue<bool>("UseDeveloperExceptionPage")) #1
app.UseDeveloperExceptionPage(); #2
else
app.UseExceptionHandler("/error"); #3
Compare the environment check for Swagger with the separate configuration-key check that chooses exception middleware. section 2.4.3

