Add Aspire.Hosting.Maui (.NET MAUI) Mac Catalyst integration#12342
Add Aspire.Hosting.Maui (.NET MAUI) Mac Catalyst integration#12342jfversluis merged 4 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 -- 12342Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12342" |
There was a problem hiding this comment.
Pull Request Overview
This PR adds Mac Catalyst platform support to Aspire's MAUI hosting capabilities, following the same architectural patterns as the existing Windows implementation. The implementation introduces a marker interface IMauiPlatformResource for unified handling of all MAUI platform resources, adds Mac Catalyst device registration through AddMacCatalystDevice(), and includes platform validation with automatic detection of macOS host support and TFM validation.
Key Changes:
- Added Mac Catalyst platform support with automatic TFM detection and OS validation
- Introduced
IMauiPlatformResourcemarker interface to unify platform-specific resource handling - Extracted common platform configuration logic into
MauiPlatformHelperto reduce code duplication
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
MauiMacCatalystExtensions.cs |
Adds extension methods for registering Mac Catalyst devices with MAUI projects |
MauiMacCatalystPlatformResource.cs |
Defines the Mac Catalyst platform resource class implementing IMauiPlatformResource |
IMauiPlatformResource.cs |
Introduces marker interface for unified handling of all MAUI platform resources |
MauiPlatformHelper.cs |
Provides shared helper methods for platform resource configuration |
UnsupportedPlatformEventSubscriber.cs |
Updated to use IMauiPlatformResource interface instead of explicit type checks |
MauiWindowsPlatformResource.cs |
Updated to implement IMauiPlatformResource interface |
MauiWindowsExtensions.cs |
Refactored to use MauiPlatformHelper for common path operations |
MauiProjectResource.cs |
Updated documentation to mention AddMacCatalystDevice |
MauiMacCatalystExtensionsTests.cs |
Comprehensive test suite for Mac Catalyst functionality |
AppHost.cs |
Playground example demonstrating Mac Catalyst usage |
| /// This interface is used to identify resources that represent a specific platform instance | ||
| /// of a MAUI application, allowing for common handling across all MAUI platforms. | ||
| /// </remarks> | ||
| internal interface IMauiPlatformResource |
There was a problem hiding this comment.
I think make this derive from IResource or maybe even IResourceWithParent.
| // Check if a Mac Catalyst device with this name already exists in the application model | ||
| var existingMacCatalystDevices = builder.ApplicationBuilder.Resources | ||
| .OfType<MauiMacCatalystPlatformResource>() | ||
| .FirstOrDefault(r => r.Parent == builder.Resource && | ||
| string.Equals(r.Name, name, StringComparisons.ResourceName)); |
There was a problem hiding this comment.
You don't actually need to two this check (in fact the check is not quite right). You can just add the resource to the model and it will do a uniqueness check on the name. You cannot have two resources with the same name even if they differ by type. Change this for the Windows resource too - I didn't pick it up in review last time ;)
mitchdenny
left a comment
There was a problem hiding this comment.
Approving assuming you'll address the feedback above. I cannot test on a Mac unfortunately. I think there might be an issue with restore.cmd -restore-maui it would be good if you could test that on Windows on a clean repo just to make sure its working the way you expect?
|
Discussed workload changes offline, @joperezr will have a look at that. Will do the other changes in the next PR. |
* Add Mac Catalyst * Better code sharing * Update README.md * Update public API file
* Android integration * Update tests and readme * Address comment in #12342 * Address other comment in #12342 * Remove duplicate name check * Add WithOtlpDevTunnel functionality * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/Aspire.Hosting.Maui/Utilities/MauiEnvironmentHelper.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Improve DCP value detection * Refactor MauiAndroidEnvironmentProcessedAnnotation marker Simplifies MauiAndroidEnvironmentProcessedAnnotation by removing the unused TargetsFilePath property and constructor. Updates usage to reflect the new parameterless constructor and clarifies documentation to indicate the annotation is a marker for callback registration. * Revert "Update src/Aspire.Hosting.Maui/Utilities/MauiEnvironmentHelper.cs" This reverts commit 8f17d90. * Share OtlpEndpointResolver * Refactor OTLP endpoint default value handling Replaces hardcoded default OTLP port and URL values with named constants and static readonly fields for improved maintainability and clarity. * Improve OTLP tunnel name * Add iOS integration * Refactor iOS env var targets file * Device/Simulator ID warning * Revert sharing OtlpResolver for now --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Description
This PR adds Mac Catalyst platform support to Aspire's MAUI hosting capabilities, mirroring the existing Windows platform implementation and following the same patterns for consistency and maintainability.
Follow up from #12284 and #11942
Features
AddMacCatalystDevice()orAddMacCatalystDevice(name)for multiple instancesnet10.0-windows10.0.19041.0) and fails fast with clear error messages if missingNew Files
IMauiPlatformResource.cs- Marker interface for all MAUI platform-specific resources (Windows, Android (tbd), iOS (tbd), Mac Catalyst). This interface enables uniform handling across all MAUI platforms and simplifies future platform additions.MauiMacCatalystExtensions.cs- Extension methods for adding Mac Catalyst devices to MAUI projects viaAddMacCatalystDevice().MauiMacCatalystPlatformResource.cs- Resource class representing a Mac Catalyst platform instance of a MAUI project.MauiMacCatalystExtensionsTests.cs- Comprehensive test suite covering Mac Catalyst resource registration, configuration, and error handling.Modified Files
MauiWindowsPlatformResource.cs- ImplementsIMauiPlatformResourceinterface for unified platform handling.UnsupportedPlatformEventSubscriber.cs- Updated to useIMauiPlatformResourceinterface check instead of explicit type checks, simplifying logic and supporting all current and future platforms.AspireWithMauito demonstrate Mac Catalyst usage alongside Windows.Public API
Usage Example
Architecture
This PR also introduces
IMauiPlatformResource, a marker interface for unified handling of all MAUI platform resources:IMauiPlatformResource: Marker interface implemented by all platform-specific resources (Windows, Mac Catalyst, and future iOS/Android)UnsupportedPlatformEventSubscriber: Simplified to use interface-based checks instead of explicit type checks, making it easier to add new platformsTesting
Contributes to #4684
Checklist
<remarks />and<code />elements on your triple slash comments?