You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: playground/AspireWithMaui/README.md
+24-7Lines changed: 24 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,10 +68,15 @@ The playground demonstrates Aspire's ability to manage MAUI apps on multiple pla
68
68
-**Windows**: Configures the MAUI app with `.AddWindowsDevice()`
69
69
-**Mac Catalyst**: Configures the MAUI app with `.AddMacCatalystDevice()`
70
70
-**Android Device**: Configures the MAUI app with `.AddAndroidDevice()` to run on physical Android devices
71
+
- Use `.AddAndroidDevice()` to target the only attached device (default, requires exactly one device)
72
+
- Use `.AddAndroidDevice("device-name", "abc12345")` to target a specific device by serial number or IP
73
+
- Works with USB-connected devices and WiFi debugging (e.g., "192.168.1.100:5555")
74
+
- Get device IDs from `adb devices` command
71
75
-**Android Emulator**: Configures the MAUI app with `.AddAndroidEmulator()` to run on Android emulators
72
-
- Use `.AddAndroidEmulator()` to target the default/running emulator
73
-
- Use `.AddAndroidEmulator(emulatorId: "Pixel_5_API_33")` to target a specific emulator
74
-
- Get emulator names from `adb devices` command
76
+
- Use `.AddAndroidEmulator()` to target the only running emulator (default)
77
+
- Use `.AddAndroidEmulator("emulator-name", "Pixel_5_API_33")` to target a specific emulator by AVD name
78
+
- Can also use emulator serial number like "emulator-5554"
79
+
- Get emulator names from `adb devices` or `emulator -list-avds` command
75
80
- Automatically detects platform-specific target frameworks from the project file
76
81
- Shows "Unsupported" state in dashboard when running on incompatible host OS
77
82
- Sets up dev tunnels for MAUI app communication with backend services
@@ -84,25 +89,37 @@ The MAUI app discovers and connects to backend services (WeatherApi) using Aspir
84
89
85
90
### Environment Variables
86
91
87
-
All MAUI platform resources support environment variables using the standard `.WithEnvironment()` method:
92
+
All MAUI platform resources support environment variables using the standard `.WithEnvironment()` method. Environment variables are automatically forwarded to the MAUI application regardless of platform:
88
93
89
94
```csharp
90
95
// For Windows and Mac Catalyst, environment variables are passed directly:
91
96
mauiapp.AddWindowsDevice()
92
97
.WithEnvironment("DEBUG_MODE", "true")
93
98
.WithEnvironment("API_TIMEOUT", "30");
94
99
95
-
// For Android, environment variables are passed via an intermediate MSBuild targets file, but the syntax to pass them is identical:
96
-
mauiapp.AddAndroidEmulator("debug-emulator")
100
+
// For Android, environment variables are passed via an intermediate MSBuild targets file, but the syntax is identical:
.WithReference(weatherApi); // Service discovery environment variables also forwarded
100
109
```
101
110
111
+
#### What Gets Forwarded
112
+
113
+
**ALL Aspire-managed environment variables** are automatically forwarded to MAUI applications:
114
+
-**Custom variables**: Set via `.WithEnvironment(key, value)`
115
+
-**Service discovery**: Connection strings and endpoints from `.WithReference(service)`
116
+
-**OpenTelemetry**: OTEL configuration from `.WithOtlpExporter()`
117
+
-**Resource metadata**: Automatically added by Aspire
118
+
102
119
#### Platform-Specific Implementation
103
120
104
121
-**Windows & Mac Catalyst**: Environment variables are passed directly through the process environment when launching via `dotnet run`.
105
-
-**Android**: Due to Android platform limitations, environment variables are written to a temporary MSBuild targets file that gets imported during the build. This happens automatically - no additional configuration required.
122
+
-**Android**: Due to Android platform limitations, environment variables are written to a temporary MSBuild targets file that gets imported during the build. The targets file is generated automatically before each build and cleaned up after 24 hours (when a next build happens). Environment variable names are normalized to UPPERCASE (Android requirement), and semicolons are encoded as `%3B`.
106
123
-**iOS**: (Coming soon) Will use a similar approach to Android with MSBuild targets file.
107
124
108
125
Environment variables are available in your MAUI app code regardless of platform through standard .NET environment APIs (`Environment.GetEnvironmentVariable()`).
0 commit comments