dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.91k stars 475 forks source link

Configure Environment of AppHost in Publish Mode #6667

Open RamType0 opened 1 week ago

RamType0 commented 1 week ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

When deploying or running Aspire, every project in Aspire has Environment(e,g, Development, Staging, Production).

When we are on Run Mode, we could specify it in launchsettings.json.

But when we are on PublishMode, we could not specify it.

I'm using workaround for this issue.

if (builder.ExecutionContext.IsPublishMode)
{
    var environmentName = builder.AddParameter("hostingEnvironment");
    var environmentVariableName = "DOTNET_ENVIRONMENT";
    apiService.WithEnvironment(environmentVariableName, environmentName);
    webFrontend.WithEnvironment(environmentVariableName, environmentName);
}

But this workaround does not works for builder.Environment of AppHost itself. Even if we are deploying for "Production" environment, builder.Environment is "Development". It is confusing.

Describe the solution you'd like

Abillity to select launchSettings.json for each publish profile.

Additional context

No response