Skip to content

Commit c8436c2

Browse files
committed
Update tests and readme
1 parent 2aaef80 commit c8436c2

File tree

5 files changed

+503
-1487
lines changed

5 files changed

+503
-1487
lines changed

playground/AspireWithMaui/README.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ The playground demonstrates Aspire's ability to manage MAUI apps on multiple pla
6868
- **Windows**: Configures the MAUI app with `.AddWindowsDevice()`
6969
- **Mac Catalyst**: Configures the MAUI app with `.AddMacCatalystDevice()`
7070
- **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
7175
- **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
7580
- Automatically detects platform-specific target frameworks from the project file
7681
- Shows "Unsupported" state in dashboard when running on incompatible host OS
7782
- 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
8489

8590
### Environment Variables
8691

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:
8893

8994
```csharp
9095
// For Windows and Mac Catalyst, environment variables are passed directly:
9196
mauiapp.AddWindowsDevice()
9297
.WithEnvironment("DEBUG_MODE", "true")
9398
.WithEnvironment("API_TIMEOUT", "30");
9499

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:
101+
mauiapp.AddAndroidDevice("my-device", "abc12345")
97102
.WithEnvironment("DEBUG_MODE", "true")
98103
.WithEnvironment("API_TIMEOUT", "30")
99104
.WithEnvironment("LOG_LEVEL", "Debug");
105+
106+
mauiapp.AddAndroidEmulator("my-emulator", "Pixel_5_API_33")
107+
.WithEnvironment("CUSTOM_VAR", "value")
108+
.WithReference(weatherApi); // Service discovery environment variables also forwarded
100109
```
101110

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+
102119
#### Platform-Specific Implementation
103120

104121
- **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`.
106123
- **iOS**: (Coming soon) Will use a similar approach to Android with MSBuild targets file.
107124

108125
Environment variables are available in your MAUI app code regardless of platform through standard .NET environment APIs (`Environment.GetEnvironmentVariable()`).

0 commit comments

Comments
 (0)