I've created a .Net 6.0 Console application. I need it to be able to migrate the database using Entity Framework. Now when I run it, it says its environment is 'Production'. Where is that configured?
Here's the startup code for the application.
static void Main(string[] args)
{
using IHost host = Host.CreateDefaultBuilder(args)
.UseSerilog((context, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(context.Configuration)
.WriteTo.Console())
.ConfigureServices((context, services) =>
{
services.RegisterCoreServices(context.Configuration);
})
.Build();
CallBatch(host.Services, args);
host.RunAsync();
}
Production is the default.
Check out Use multiple environments in ASP.NET Core
Environments
To determine the runtime environment, ASP.NET Core reads from the following environment variables:
- DOTNET_ENVIRONMENT
- ASPNETCORE_ENVIRONMENT when the WebApplication.CreateBuilder method is called. The default ASP.NET Core web app templates call WebApplication.CreateBuilder. The ASPNETCORE_ENVIRONMENT value overrides DOTNET_ENVIRONMENT.
IHostEnvironment.EnvironmentName can be set to any value, but the following values are provided by the framework:
- Development: The launchSettings.json file sets ASPNETCORE_ENVIRONMENT to Development on the local machine.
- Staging
- Production: The default if DOTNET_ENVIRONMENT and ASPNETCORE_ENVIRONMENT have not been set.