Read ASPIRE_ENVIRONMENT in DistributedApplicationBuilder#16098
Open
Read ASPIRE_ENVIRONMENT in DistributedApplicationBuilder#16098
Conversation
Contributor
|
🚀 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
reviewed
Apr 13, 2026
JamesNK
reviewed
Apr 13, 2026
Member
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.
tests/Aspire.Cli.EndToEnd.Tests/Helpers/CaptureWorkspaceOnFailureAttribute.cs
Outdated
Show resolved
Hide resolved
32c5ff4 to
8536962
Compare
f46f348 to
6a172fa
Compare
JamesNK
approved these changes
Apr 13, 2026
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 <223556219+Copilot@users.noreply.github.com>
6a172fa to
358336b
Compare
Contributor
|
🎬 CLI E2E Test Recordings — 68 recordings uploaded (commit View recordings
📹 Recordings uploaded automatically from CI run #24325469900 |
eerhardt
reviewed
Apr 13, 2026
| private static RemoteInvokeOptions CreateEnvironmentOptions( | ||
| string? aspireEnvironment = null, | ||
| string? dotnetEnvironment = null, | ||
| string? aspNetCoreEnvironment = null) |
Member
There was a problem hiding this comment.
When do we use aspNetCoreEnvironment?
eerhardt
reviewed
Apr 13, 2026
|
|
||
| // 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. |
eerhardt
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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