Hi Kazys! Good to hear from you.
In an ASP.NET Core application, the runtime selects the environment (Development, Staging, Production, etc.) based on the ASPNETCORE_ENVIRONMENT environment variable. Here's how it works:
Environment Variable Setting:
Each profile in launchSettings.json sets the ASPNETCORE_ENVIRONMENT variable (e.g., "Development").
Runtime Selection:
When the application starts, the runtime reads ASPNETCORE_ENVIRONMENT to determine which environment-specific configuration to load, such as appsettings.Development.json.
Switching Profiles:
Locally: In Visual Studio, switch profiles using the dropdown to set the environment variable.
Its located near the start button where you can select IIS Express or your project name.
Deployment: On servers or in cloud environments, set the ASPNETCORE_ENVIRONMENT variable to control the environment.
This setup ensures the application loads the correct configuration and services based on the environment it's running in.
Kazys Račkauskas
Tdd
I don't work much with ASP.NET, and when I do, I usually stick to the default settings in launchSettings.json. So, it was nice to get more familiar with launchSettings.json through your article. One question: How is the switch between profiles made? How does the runtime know which profile to use?