Add Aspire.Hosting.Maui (.NET MAUI) integration#11942
Add Aspire.Hosting.Maui (.NET MAUI) integration#11942jfversluis wants to merge 50 commits intomainfrom
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 11942Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 11942" |
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive .NET MAUI integration to .NET Aspire, enabling developers to orchestrate MAUI applications alongside backend services through the Aspire app host. The integration provides unified telemetry, service discovery, and multi-platform support (Windows, Android, iOS, macCatalyst) with dev tunnels for device communication.
- Implements complete MAUI hosting infrastructure with platform-specific resource management and auto-detection capabilities
- Adds comprehensive test coverage for platform selection, visualization, error handling, and telemetry integration
- Includes a fully functional playground demonstrating MAUI-Aspire integration with weather API consumption
Reviewed Changes
Copilot reviewed 77 out of 85 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
src/Aspire.Hosting.Maui/ |
Core MAUI hosting implementation with platform detection, resource management, and dev tunnels support |
tests/Aspire.Hosting.Maui.Tests/ |
Comprehensive test suite covering platform selection, visualization, duplicate handling, and error scenarios |
playground/AspireWithMaui/ |
Complete playground demonstrating MAUI-Aspire integration with weather API, telemetry, and multi-platform support |
Comments suppressed due to low confidence (1)
tests/Aspire.Hosting.Maui.Tests/MauiUnsupportedPlatformTests.cs:1
- Replace string-based type name matching with proper type checking using
OfType<MauiUnsupportedPlatformAnnotation>()for type safety and better performance.
// Licensed to the .NET Foundation under one or more agreements.
playground/AspireWithMaui/AspireWithMaui.MauiServiceDefaults/Extensions.cs
Outdated
Show resolved
Hide resolved
src/Aspire.Hosting.Maui/Platforms/Android/AndroidEnvironmentTargetGenerator.cs
Outdated
Show resolved
Hide resolved
playground/AspireWithMaui/AspireWithMaui.MauiClient/EnvironmentPage.xaml.cs
Outdated
Show resolved
Hide resolved
|
I've excluded the MAUIClient playground sample from building right now, building locally should work as expected. Open to any other suggestions to fix this better. It’s really just the MAUI app though, the AppHost does build, so whenever the API changes it should still detect that. The downside is if we do want to build it, we're probably adding minutes to install the workload and actually building the app to the pipeline which doesn't seem ideal. |
| /// Tracks completion of the initial AppHost startup phase so MAUI platform resources can | ||
| /// defer expensive build work until the user explicitly starts them later. | ||
| /// </summary> | ||
| internal sealed class MauiStartupPhaseTracker : IDistributedApplicationEventingSubscriber |
There was a problem hiding this comment.
I don't know if you want to do it this way. OnAfterResourcesCreatedAsync runs after all of the wait fors resolve.
There was a problem hiding this comment.
What I ran into, but maybe this is simply something I'm overlooking...
If I use OnAfterResourcesCreatedAsync that will still build the project, right? Even if I do WithExplicitStart(). That will add minutes to starting the AppHost project and then maybe users won't even launch the MAUI app for this run.
That's why I did it like this to explicitly not build the MAUI project until someone really presses the start button.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…xtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
b1cb3eb to
b1d25f1
Compare
|
Discussed this with the Aspire team. We're going to do this, but with a different API surface. Closing this one and getting things implemented through smaller PRs. The first one is here: #12284 as such, closing this one. Stay tuned! |
Description
Have a look at a live demo in the last .NET MAUI Community Standup.
Adds Aspire integration with .NET MAUI applications, showcasing multi-platform support (Windows, Android, iOS, macCatalyst) with dev tunnels and OpenTelemetry integration. Including a playground to demonstrate the new APIs and functionality.
This functionality targets only the developer experience. There is no scenario where I see this ever be useful with deploying. However, the MAUI integration will still be very valuable.
It is intentionally only implemented with the project path reference and not package reference to avoid multi-targeting behaviors and bugs (see #3043).
Additionally, I am deliberately delaying the MAUI project build to when a user hits the start button. While it then might take a while for the MAUI app to pop up, this avoids having a multiple minutes startup time for the AppHost. The assumption here is that users will want to see their application landscape fast, and then pick only 1 platform at a time to focus on. The first build of a MAUI project will be slower (probably Android slowest with ~3 minutes of build time depending on your machines specs), incremental builds will be faster. Advantage of this approach is also: each time the start button is clicked the project builds which makes it easier to make code changes and test them out without having to restart the whole AppHost (glass half full!)
Lastly, special mention for the environment variables specifically for iOS and Android. Those are written to an intermediary targets file and added as part of the
dotnet runcommand. Since the apps won't be running on the same machine as the AppHost, we need to transport the (relevant) environment variables to the emulator/Simulator/device. .NET for iOS and .NET for Android have functionality for that in their SDK, so we're leveraging that. To not litter developers systems with targets file they are being pruned after 1 day.What's Included
V1 Features
AddMauiProject()- Adds the MAUI project to the AppHost.WithWindows()- Run MAUI app on Windows.WithAndroid()- Run MAUI app on Android device/emulator.WithiOS()- Run MAUI app on iOS device/simulator.WithMacCatalyst()- Run MAUI app on macOS via Catalyst.WithiOS()called on Windows), can be worked around withif (OperatingSystem.IsWindows())checks while building the MAUI project resource.AddMauiProject()but forgetsWithiOS()(or any other platform) we automatically detect the platforms from the MAUI project and add them (only the supported platforms for the host that we're running on). Additionally, a warning is given to hint the user to do it explicitly themselves..dotnetfolder without affecting system-wide installation (augments the root restore script)Current Behavior (and known limitations/issues)
.WithiOS(), a random simulator is selected automatically (which is a good thing!)Potential Future Improvements
Open Questions (also future improvements)
Fixes #4684
Checklist
<remarks />and<code />elements on your triple slash comments?