-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Only enable Aspire functionality in non-optimized builds (i.e. Debug) #31494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
...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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the IsAndroid() check if it's inside #if ANDROID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not! Double safe!

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]