KEMBAR78
Only enable Aspire functionality in non-optimized builds (i.e. Debug) by jfversluis · Pull Request #31494 · dotnet/maui · GitHub
Skip to content

Conversation

@jfversluis
Copy link
Member

@jfversluis jfversluis commented Sep 5, 2025

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

  • Added a new feature switch, EnableMauiAspire, to the RuntimeFeature class, with default logic and AppContext support for runtime configuration. [1] [2]
  • Updated build targets (Microsoft.Maui.Controls.targets) to automatically set the _EnableMauiAspire property based on build optimization settings, and emit a warning (MA002) if the property is manually set in an optimized build. [1] [2]
  • Ensured the runtime host configuration option for EnableMauiAspire is included in the build output when appropriate.

Documentation

  • Added documentation for the new _EnableMauiAspire switch in FeatureSwitches.md, including default values, automatic configuration behavior, manual override warning, and trimming implications. [1] [2]

Platform-Specific Behavior

  • Updated AppHostBuilderExtensions.cs to check RuntimeFeature.EnableMauiAspire before configuring environment variables, and added Android-specific logic to read environment variables from a device file if present. [1] [2]

@Copilot Copilot AI review requested due to automatic review settings September 5, 2025 09:21
@jfversluis jfversluis requested a review from a team as a code owner September 5, 2025 09:21
@jfversluis jfversluis added the area-aspire Work that has to do with the Aspire integration label Sep 5, 2025
Copilot

This comment was marked as outdated.

Copy link
Contributor

Copilot AI left a 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 EnableMauiAspire runtime 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

jfversluis and others added 2 commits September 5, 2025 15:21
…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 jfversluis changed the title Only enable Aspire functionality in debug Only enable Aspire functionality in non-optimized builds (i.e. Debug) Sep 8, 2025
Copy link
Member

@jonathanpeppers jonathanpeppers left a 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))
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not! Double safe!

@jfversluis
Copy link
Member Author

Debut of the Peppers seal of approval!

image

@jfversluis jfversluis merged commit d4829b8 into net10.0 Sep 9, 2025
138 of 150 checks passed
@jfversluis jfversluis deleted the enable-aspire-runtimefeature branch September 9, 2025 17:35
@github-actions github-actions bot locked and limited conversation to collaborators Oct 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-aspire Work that has to do with the Aspire integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants