What is ASPNETCORE_ENVIRONMENT used for?

BeginnerConcept.NET builds (dotnet CLI)
Answer

Short answer

It tells an ASP.NET Core app which environment it's running in — usually Development, Staging or Production. The app uses it to load appsettings.{Environment}.json, and code can behave differently per environment (for example detailed error pages only in Development).

Example

ASPNETCORE_ENVIRONMENT=Staging dotnet Shop.Api.dll
# loads appsettings.json, then appsettings.Staging.json
if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();     // stack traces — never in production
    app.UseSwagger(); app.UseSwaggerUI();
}

Default

If it isn't set, the app assumes Production. That's a safe default — but a classic mistake is forgetting to set it in a staging environment and getting production settings there.

Related

DOTNET_ENVIRONMENT does the same for non-web (worker/console) apps.

What to say in the interview

"ASPNETCORE_ENVIRONMENT selects the environment-specific appsettings file and toggles environment-specific behaviour like developer exception pages. It defaults to Production, and we set it explicitly per environment in the Deployment or App Service settings."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: .NET apps: dotnet build & publish

More on .NET builds (dotnet CLI)