Skip to content

Commit 5fc6849

Browse files
committed
Scripts separate flag for installing MAUI workload
1 parent d2f0607 commit 5fc6849

File tree

5 files changed

+64
-40
lines changed

5 files changed

+64
-40
lines changed

eng/build.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function Get-Help() {
4444
Write-Host "Libraries settings:"
4545
Write-Host " -testnobuild Skip building tests when invoking -test."
4646
Write-Host " -buildExtension Build the VS Code extension."
47+
Write-Host " -restore-maui Restore the MAUI workload after restore (only on Windows/macOS)."
4748
Write-Host ""
4849

4950
Write-Host "Command-line arguments not listed above are passed through to MSBuild."
@@ -111,11 +112,11 @@ Write-Host "& `"$PSScriptRoot/common/build.ps1`" $arguments"
111112
Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $arguments"
112113
$buildExitCode = $LASTEXITCODE
113114

114-
# Install MAUI workload after restore if -restore was passed
115+
# Install MAUI workload after restore if -restore-maui was passed
115116
# Only on Windows and macOS (MAUI doesn't support Linux)
116-
$restoreRequested = ($PSBoundParameters.ContainsKey('restore') -or $arguments -like '*-restore*')
117+
$restoreMauiPassed = $properties -contains "-restore-maui"
117118
$isWindowsOrMac = ($IsWindows -or $IsMacOS -or (-not (Get-Variable -Name IsWindows -ErrorAction SilentlyContinue)))
118-
if ($restoreRequested -and $buildExitCode -eq 0 -and $isWindowsOrMac) {
119+
if ($restoreMauiPassed -and $buildExitCode -eq 0 -and $isWindowsOrMac) {
119120
Write-Host ""
120121
Write-Host "Installing MAUI workload into local .dotnet..."
121122

eng/build.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ usage()
4646
echo "Libraries settings:"
4747
echo " --testnobuild Skip building tests when invoking -test."
4848
echo " --build-extension Build the VS Code extension."
49+
echo " --restore-maui Restore the MAUI workload after restore (only on macOS)."
4950
echo ""
5051

5152
echo "Command line arguments starting with '/p:' are passed through to MSBuild."
@@ -55,6 +56,7 @@ usage()
5556

5657
arguments=''
5758
extraargs=''
59+
restore_maui=false
5860

5961
# Check if an action is passed in
6062
declare -a actions=("b" "build" "r" "restore" "rebuild" "testnobuild" "sign" "publish" "clean" "t" "test" "build-extension")
@@ -142,6 +144,11 @@ while [[ $# > 0 ]]; do
142144
shift 1
143145
;;
144146

147+
-restore-maui)
148+
restore_maui=true
149+
shift 1
150+
;;
151+
145152
*)
146153
extraargs="$extraargs $1"
147154
shift 1
@@ -161,9 +168,9 @@ arguments="$arguments $extraargs"
161168
"$scriptroot/common/build.sh" $arguments
162169
buildExitCode=$?
163170

164-
# Install MAUI workload after restore if --restore was passed
171+
# Install MAUI workload after restore if --restore-maui was passed
165172
# Only on macOS (MAUI doesn't support Linux, Windows uses .cmd)
166-
if [[ "$arguments" == *"-restore"* ]] && [ $buildExitCode -eq 0 ]; then
173+
if [ "$restore_maui" = true ] && [ $buildExitCode -eq 0 ]; then
167174
# Check if we're on macOS
168175
if [[ "$(uname -s)" == "Darwin" ]]; then
169176
echo ""

playground/AspireWithMaui/README.md

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,98 +5,114 @@ This playground demonstrates .NET Aspire integration with .NET MAUI applications
55
## Prerequisites
66

77
- .NET 10 or later
8-
- .NET MAUI workload (will be installed automatically by the restore script)
8+
- .NET MAUI workload
99

1010
## Getting Started
1111

1212
### Initial Setup
1313

14-
Before building or running the playground, you must restore dependencies and install the MAUI workload:
14+
Before building or running the playground, you must restore dependencies and install the MAUI workload.
15+
16+
Run the following commands from the repository root:
1517

1618
**Windows:**
1719
```cmd
18-
restore.cmd
20+
.\restore.cmd -restore-maui
1921
```
2022

2123
**Linux/macOS:**
2224
```bash
23-
./restore.sh
25+
./restore.sh --restore-maui
2426
```
2527

26-
This script will:
27-
1. Run the main Aspire restore to set up the local .dotnet SDK
28-
2. Install the MAUI workload into the local `.dotnet` folder (does not affect your global installation)
28+
This will:
29+
1. Restore all Aspire dependencies and set up the local .dotnet SDK
30+
2. Install the MAUI workload into the repository's local `.dotnet` folder (does not affect your global installation)
2931

3032
> **Note:** The MAUI workload is installed only in the repository's local `.dotnet` folder and will not interfere with your system-wide .NET installation.
33+
> This also means that you will still need to do this even if you have the MAUI workload already installed in your system-wide .NET installation.
3134
3235
### Running the Playground
3336

34-
After running the restore script, you can build and run the playground:
37+
After running the restore script with `-restore-maui`, you can build and run the playground:
3538

3639
**Using Visual Studio:**
37-
1. Run `restore.cmd` (Windows) or `./restore.sh` (Linux/macOS)
40+
1. Run `.\restore.cmd -restore-maui` from the repository root (Windows)
3841
2. Open `AspireWithMaui.AppHost` project
3942
3. Set it as the startup project
4043
4. Press F5 to run
4144

4245
**Using VS Code:**
43-
1. Run `restore.cmd` (Windows) or `./restore.sh` (Linux/macOS)
46+
1. Run `.\restore.cmd -restore-maui` (Windows) or `./restore.sh --restore-maui` (Linux/macOS) from the repository root
4447
2. From the repository root, run: `./start-code.sh` or `start-code.cmd`
4548
3. Open the `AspireWithMaui` folder
4649
4. Use the debugger to run the AppHost
4750

4851
**Using Command Line:**
49-
1. Run `restore.cmd` (Windows) or `./restore.sh` (Linux/macOS)
50-
2. Navigate to `AspireWithMaui.AppHost` directory
52+
1. Run `.\restore.cmd -restore-maui` (Windows) or `./restore.sh --restore-maui` (Linux/macOS) from the repository root
53+
2. Navigate to `playground/AspireWithMaui/AspireWithMaui.AppHost` directory
5154
3. Run: `dotnet run`
5255

5356
## What's Included
5457

5558
- **AspireWithMaui.AppHost** - The Aspire app host that orchestrates all services
56-
- **AspireWithMaui.MauiClient** - A .NET MAUI application that connects to the backend
59+
- **AspireWithMaui.MauiClient** - A .NET MAUI application that connects to the backend (Windows platform only in this playground)
5760
- **AspireWithMaui.WeatherApi** - An ASP.NET Core Web API providing weather data
5861
- **AspireWithMaui.ServiceDefaults** - Shared service defaults for non-MAUI projects
5962
- **AspireWithMaui.MauiServiceDefaults** - Shared service defaults specific to MAUI projects
6063

6164
## Features Demonstrated
6265

63-
### MAUI Platform Support
64-
The playground demonstrates Aspire's ability to manage MAUI apps across multiple platforms:
65-
- Windows
66-
- Android
67-
- iOS
68-
- macCatalyst
66+
### MAUI Windows Platform Support
67+
The playground demonstrates Aspire's ability to manage MAUI apps on Windows:
68+
- Configures the MAUI app with `.AddMauiWindows()`
69+
- Automatically detects the Windows target framework from the project file
70+
- Sets up dev tunnels for MAUI app communication with backend services
6971

7072
### OpenTelemetry Integration
7173
The MAUI client uses OpenTelemetry to send traces and metrics to the Aspire dashboard via dev tunnels.
7274

7375
### Service Discovery
7476
The MAUI app discovers and connects to backend services (WeatherApi) using Aspire's service discovery.
7577

76-
### Multi-Platform Development
77-
The AppHost shows how to:
78-
- Configure different platforms with `.WithWindows()`, `.WithAndroid()`, `.WithiOS()`, `.WithMacCatalyst()`
79-
- Set up dev tunnels for MAUI app communication
80-
- Reference backend services from MAUI apps
78+
### Future Platform Support
79+
The architecture is designed to support additional platforms (Android, iOS, macCatalyst) through:
80+
- `.AddMauiAndroid()`, `.AddMauiIos()`, `.AddMauiMacCatalyst()` extension methods (coming in future updates)
81+
- Parallel extension patterns for each platform
8182

8283
## Troubleshooting
8384

8485
### "MAUI workload not detected" Warning
8586
If you see this warning in the Aspire dashboard:
86-
1. Make sure you ran `restore.cmd` or `./restore.sh` in the `playground/AspireWithMaui` directory
87+
1. Make sure you ran `.\restore.cmd -restore-maui` or `./restore.sh --restore-maui` from the repository root
8788
2. The warning indicates the MAUI workload is not installed in the local `.dotnet` folder
88-
3. Re-run the restore script to install it
89+
3. Re-run the restore command with the `-restore-maui` or `--restore-maui` flag
8990

9091
### Build Errors
9192
If you encounter build errors:
92-
1. Ensure you ran the restore script first
93+
1. Ensure you ran the restore script with the MAUI flag first: `.\restore.cmd -restore-maui`
9394
2. Make sure you're using .NET 10 RC or later
9495
3. Try running `dotnet build` from the repository root first
9596

9697
### Platform-Specific Issues
9798
- **Windows**: Requires Windows 10 build 19041 or higher for WinUI support
98-
- **Android**: Requires Android SDK and emulator/device
99-
- **iOS/macCatalyst**: Requires macOS with Xcode installed
99+
- **Android**: Not yet implemented in this playground (coming soon)
100+
- **iOS/macCatalyst**: Not yet implemented in this playground (coming soon)
101+
102+
## Current Status
103+
104+
**Implemented:**
105+
- Windows platform support via `AddMauiWindows()`
106+
- Automatic Windows TFM detection from project file
107+
- Dev tunnel configuration for MAUI-to-backend communication
108+
- Service discovery integration
109+
- OpenTelemetry integration
110+
111+
🚧 **Coming Soon:**
112+
- Android platform support
113+
- iOS platform support
114+
- macCatalyst platform support
115+
- Multi-platform simultaneous debugging
100116

101117
## Learn More
102118

playground/AspireWithMaui/restore.cmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ ECHO Restoring AspireWithMaui Playground
77
ECHO ============================================================
88
ECHO.
99

10-
REM Run the main Aspire restore (which now includes MAUI workload installation)
11-
ECHO Running main Aspire restore (includes MAUI workload installation)...
12-
CALL "%~dp0..\..\restore.cmd"
10+
REM Run the main Aspire restore with MAUI workload installation
11+
ECHO Running main Aspire restore with MAUI workload installation...
12+
CALL "%~dp0..\..\restore.cmd" -installMaui
1313
IF ERRORLEVEL 1 (
1414
ECHO ERROR: Failed to restore Aspire. Please check the output above.
1515
EXIT /B 1

playground/AspireWithMaui/restore.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ echo ""
1212
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1313
repo_root="$script_dir/../.."
1414

15-
# Run the main Aspire restore (which now includes MAUI workload installation)
16-
echo "Running main Aspire restore (includes MAUI workload installation)..."
17-
"$repo_root/restore.sh"
15+
# Run the main Aspire restore with MAUI workload installation
16+
echo "Running main Aspire restore with MAUI workload installation..."
17+
"$repo_root/restore.sh" --install-maui
1818

1919
echo ""
2020
echo "============================================================"

0 commit comments

Comments
 (0)