- 
                Notifications
    You must be signed in to change notification settings 
- Fork 715
Add Aspire.Hosting.Maui (.NET MAUI) Mac Catalyst integration #12342
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
| 🚀 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.
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 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 IMauiPlatformResourceinterface instead of explicit type checks | 
| MauiWindowsPlatformResource.cs | Updated to implement IMauiPlatformResourceinterface | 
| MauiWindowsExtensions.cs | Refactored to use MauiPlatformHelperfor 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think make this derive from IResource or maybe even IResourceWithParent.
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.
Addressed in commit ce2c2ef
| // 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ;)
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.
Addressed in commit 669549a
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.
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
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?