-
Notifications
You must be signed in to change notification settings - Fork 724
Add Aspire.Hosting.Maui (.NET MAUI) iOS integration #12402
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://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12402Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12402" |
|
Builds on top of #12381, will rebase when that one gets merged to clean this one up, that's why its a draft for now. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
…r.cs" This reverts commit 8f17d90.
Replaces hardcoded default OTLP port and URL values with named constants and static readonly fields for improved maintainability and clarity.
cf7bd8d to
8580283
Compare
mitchdenny
left a comment
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.
Provided there are no functional changes and this is just refactoring the OTLP bits into shared code for reuse this is fine. That said I cannot validate the end to end for macOS.
Description
This PR adds iOS platform support to Aspire's MAUI hosting capabilities, enabling developers to run and debug MAUI applications on iOS simulators and physical devices directly from Aspire. The implementation follows the same architectural patterns as the existing Windows, Mac Catalyst, and Android implementations and includes validation to help developers avoid common device/simulator ID mistakes.
Follow up from #12284 and #11942 and #12342 and #12381
Contributes to #4684
Features
AddiOSSimulator()orAddiOSSimulator(name, simulatorId)for targeting specific simulators by UDIDAddiOSDevice()orAddiOSDevice(name, deviceId)for targeting specific devices by UDID (requires device provisioning)net10.0-ios) and fails fast with clear error messages if missingMlaunchEnvironmentVariablesItemGroup patternWithOtlpDevTunnel()extension method for OpenTelemetry connectivity from iOS platforms that cannot reach localhostNew Files
MauiiOSExtensions.cs- Extension methods for adding iOS devices and simulators viaAddiOSDevice()andAddiOSSimulator()MauiiOSDeviceResource.cs- Resource class representing a physical iOS device instanceMauiiOSSimulatorResource.cs- Resource class representing an iOS simulator instanceUtilities/MauiiOSEnvironmentAnnotation.cs- Annotation that triggers MSBuild targets file generation for iOS environment variablesLifecycle/MauiiOSEnvironmentSubscriber.cs- Event subscriber that generates MSBuild targets files for iOS environment variablesModified Files
MauiEnvironmentHelper.cs- Added iOS-specific methods:CreateiOSEnvironmentTargetsFileAsync()- Generates targets file withMlaunchEnvironmentVariablesItemGroupGenerateiOSTargetsFileContent()- Creates XML content for iOS environment forwardingMauiHostingExtensions.cs- RegisteredMauiiOSEnvironmentSubscriberfor iOS lifecycle managementMauiOtlpExtensions.cs- Updated to support iOS resources withWithOtlpDevTunnel()api/Aspire.Hosting.Maui.cs- Updated API surface with new iOS extension methodsAspireWithMauito demonstrate iOS simulator/device usage with OTLP dev tunnelPublic API
Usage Example
Architecture
iOS Environment Variable Forwarding
iOS applications launched via
dotnet runwithmlaunchcan receive environment variables through MSBuild'sMlaunchEnvironmentVariablesproperty. This PR implements automatic environment variable forwarding:BeforeResourceStartedEventfor iOS resources.targetsfile containing<MlaunchEnvironmentVariables Include="KEY=VALUE" />items-p:CustomAfterMicrosoftCommonTargets={targetsPath}to pass the file to MSBuild%3Bto prevent MSBuild item separator issuesDevice ID Validation
To help developers avoid common mistakes when specifying iOS device/simulator UDIDs, this PR includes validation:
Guid.TryParse()to detect GUID-format IDs (iOS Simulator UDIDs are standard GUIDs)OnBeforeResourceStarted()hook, displaying errors in the dashboardAddiOSDevice()throws exception if GUID-format ID is detected (likely a simulator ID)AddiOSSimulator()throws exception if non-GUID format ID is detected (likely a device ID)Example validation error:
Checklist
<remarks />and<code />elements on your triple slash comments?