Read ASPIRE_ENVIRONMENT in DistributedApplicationBuilder#16098
Read ASPIRE_ENVIRONMENT in DistributedApplicationBuilder#16098
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16098Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16098" |
4348322 to
8f2fa03
Compare
4fd32e8 to
587315a
Compare
JamesNK
left a comment
There was a problem hiding this comment.
2 issues flagged: 1 security concern (environment variable dump in test artifacts), 1 unused constant.
32c5ff4 to
8536962
Compare
f46f348 to
6a172fa
Compare
Add ASPIRE_-prefixed environment variables as a configuration source in DistributedApplicationBuilder, using the same AddEnvironmentVariables pattern as the core framework uses for DOTNET_-prefixed variables. Priority order (highest to lowest): 1. --environment CLI flag 2. DOTNET_ENVIRONMENT 3. ASPIRE_ENVIRONMENT 4. Default (Production) Fixes #16096 Co-authored-by: Copilot <[email protected]>
6a172fa to
358336b
Compare
| private static RemoteInvokeOptions CreateEnvironmentOptions( | ||
| string? aspireEnvironment = null, | ||
| string? dotnetEnvironment = null, | ||
| string? aspNetCoreEnvironment = null) |
There was a problem hiding this comment.
When do we use aspNetCoreEnvironment?
|
|
||
| // Pre-seed the configuration with ASPIRE_-prefixed environment variables. | ||
| // HostApplicationBuilder will then add DOTNET_-prefixed env vars and command line args on top. | ||
| // This gives us the priority order: --environment > DOTNET_ENVIRONMENT > ASPIRE_ENVIRONMENT > default. |
|
Tested the dogfood build for this PR (13.3.0-pr.16098.g358336bd) on a clean droplet. Findings:
So this looks narrower than "C# vs TypeScript": project-based C# is already doing the expected publish behavior, while the guest/single-file publish/deploy paths still appear to default to Development. |
Honor --environment precedence while keeping run flows on Development and publish-like commands on Production for guest and single-file AppHosts. Co-authored-by: Copilot <[email protected]>
Keep CLI environment behavior aligned with the builder contract by only materializing DOTNET_ENVIRONMENT while still filtering ASPNETCORE_ENVIRONMENT from launch-profile env selection for publish-like commands. Co-authored-by: Copilot <[email protected]>
Keep ASPNETCORE_ENVIRONMENT handling internal to the CLI helper while preserving the updated environment selection behavior. Co-authored-by: Copilot <[email protected]>
|
🎬 CLI E2E Test Recordings — 71 recordings uploaded (commit View recordings
📹 Recordings uploaded automatically from CI run #24384051660 |
* Read ASPIRE_ENVIRONMENT in DistributedApplicationBuilder Add ASPIRE_-prefixed environment variables as a configuration source in DistributedApplicationBuilder, using the same AddEnvironmentVariables pattern as the core framework uses for DOTNET_-prefixed variables. Priority order (highest to lowest): 1. --environment CLI flag 2. DOTNET_ENVIRONMENT 3. ASPIRE_ENVIRONMENT 4. Default (Production) Fixes #16096 Co-authored-by: Copilot <[email protected]> * Fix CLI AppHost environment defaults Honor --environment precedence while keeping run flows on Development and publish-like commands on Production for guest and single-file AppHosts. Co-authored-by: Copilot <[email protected]> * Stop synthesizing ASPNETCORE_ENVIRONMENT Keep CLI environment behavior aligned with the builder contract by only materializing DOTNET_ENVIRONMENT while still filtering ASPNETCORE_ENVIRONMENT from launch-profile env selection for publish-like commands. Co-authored-by: Copilot <[email protected]> * Hide ASPNETCORE env helper constant Keep ASPNETCORE_ENVIRONMENT handling internal to the CLI helper while preserving the updated environment selection behavior. Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
Summary
ASPIRE_ENVIRONMENTis the Aspire-native, language-agnostic way to set the environment. Previously it was only read by the Aspire CLI, not by the AppHost itself, meaning it was silently ignored when running viadotnet run, azd, or any non-CLI launch path.This PR adds
ASPIRE_-prefixed environment variables as a configuration source inDistributedApplicationBuilder, using the sameAddEnvironmentVariables(prefix:)pattern as the core framework uses forDOTNET_-prefixed variables.Priority order
--environmentCLI flagdotnet run -- --environment ProductionDOTNET_ENVIRONMENTexport DOTNET_ENVIRONMENT=StagingASPIRE_ENVIRONMENTexport ASPIRE_ENVIRONMENT=StagingProductionChanges
src/Aspire.Hosting/DistributedApplicationBuilder.cs— Pre-seedConfigurationManagerwithAddEnvironmentVariables(prefix: "ASPIRE_")before passing toHostApplicationBuildertests/Aspire.Hosting.Tests/AspireEnvironmentTests.cs— 5 unit tests usingRemoteExecutorwith sharedCreateEnvironmentOptionshelpertests/Aspire.Cli.EndToEnd.Tests/AspireEnvironmentTests.cs— 2 E2E tests verifying--environmentandASPIRE_ENVIRONMENTflow through to publishtests/Aspire.Cli.EndToEnd.Tests/Helpers/CaptureWorkspaceOnFailureAttribute.cs— Capture filtered env vars on failure; preserve workspace locally for debuggingtests/Shared/TemporaryRepo.cs— Preserve workspace on disk when tests fail locally (skip cleanup outside CI)Test coverage
AspireEnvironmentSetsBuilderEnvironmentASPIRE_ENVIRONMENT=Staging→StagingDotnetEnvironmentTakesPrecedenceOverAspireEnvironmentDOTNET_ENVIRONMENTwinsEnvironmentFlagTakesPrecedenceOverAspireEnvironment--environmentwinsDefaultEnvironmentIsProductionWithNoEnvVarsProductionAspireEnvironmentSetsCustomEnvironmentNamePublishWithEnvironmentFlagSetsEnvironmentName--environment Stagingand defaultProductionAspireEnvironmentEnvVarSetsEnvironmentNameASPIRE_ENVIRONMENT=StagingFixes #16096