Only enable Aspire functionality in non-optimized builds (i.e. Debug)#31494
Merged
jfversluis merged 8 commits intonet10.0from Sep 9, 2025
Merged
Only enable Aspire functionality in non-optimized builds (i.e. Debug)#31494jfversluis merged 8 commits intonet10.0from
jfversluis merged 8 commits intonet10.0from
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces conditional Aspire integration support for .NET MAUI applications by adding build-time configuration and runtime feature flags. The integration is automatically enabled only in Debug builds to avoid performance and security risks in production releases.
Key changes:
- Adds a new
EnableMauiAspireruntime feature flag that defaults to false but can be controlled via MSBuild properties - Implements conditional environment variable handling that respects the Aspire flag and includes Android-specific file-based environment variable loading
- Introduces MSBuild validation to warn developers about manually overriding Aspire settings outside of Debug configuration
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Core/src/RuntimeFeature.cs | Adds the EnableMauiAspire feature flag with default value false and .NET 9+ feature switch support |
| src/Core/src/Hosting/Dispatching/AppHostBuilderExtensions.cs | Updates environment variable configuration to respect the Aspire flag and adds Android-specific file reading logic |
| src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets | Configures the _EnableMauiAspire property based on build configuration and adds validation warnings |
...ontrols/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets
Outdated
Show resolved
Hide resolved
…2.0/Microsoft.Maui.Controls.targets Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
jfversluis
commented
Sep 5, 2025
...ontrols/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets
Outdated
Show resolved
Hide resolved
...ontrols/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets
Outdated
Show resolved
Hide resolved
simonrozsival
approved these changes
Sep 9, 2025
jonathanpeppers
approved these changes
Sep 9, 2025
Member
jonathanpeppers
left a comment
There was a problem hiding this comment.
This looks good now, just the one minor question.
|
|
||
| // For Android we read the environment variables from a text file that is written to the device/emulator | ||
| // If the file not exists, we will use the default environment variables which is less stable | ||
| if (OperatingSystem.IsAndroid() && System.IO.File.Exists(androidEnvVarFilePath)) |
Member
There was a problem hiding this comment.
Do we need the IsAndroid() check if it's inside #if ANDROID?
Member
Author
There was a problem hiding this comment.
Probably not! Double safe!
Member
Author
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.

TL;DR: enable Aspire integration only for non optimized build (MS Build property
Optimize== false), with an option to override, but that will trigger a warning to discourage the user.This pull request introduces a new feature switch,
EnableMauiAspire, to control the availability of MAUI Aspire integration features at runtime. The changes ensure Aspire features are enabled by default in Debug builds and disabled in optimized (Release) builds, with automatic configuration and safety checks to prevent misuse in production. Documentation and warnings are added to guide developers and avoid performance or security issues.Feature: MAUI Aspire Integration
EnableMauiAspire, to theRuntimeFeatureclass, with default logic and AppContext support for runtime configuration. [1] [2]Microsoft.Maui.Controls.targets) to automatically set the_EnableMauiAspireproperty based on build optimization settings, and emit a warning (MA002) if the property is manually set in an optimized build. [1] [2]EnableMauiAspireis included in the build output when appropriate.Documentation
_EnableMauiAspireswitch inFeatureSwitches.md, including default values, automatic configuration behavior, manual override warning, and trimming implications. [1] [2]Platform-Specific Behavior
AppHostBuilderExtensions.csto checkRuntimeFeature.EnableMauiAspirebefore configuring environment variables, and added Android-specific logic to read environment variables from a device file if present. [1] [2]