-
Notifications
You must be signed in to change notification settings - Fork 825
Description
Description
Was playing around with the Maui Aspire integration, and started getting some errors. copilot did some troubleshooting, and well, when using AddAndroidEmulator() or AddAndroidDevice() in an Aspire AppHost, the Android resource immediately fails to start with:
Error: Unexpected argument(s): run
Try 'Microsoft.Android.Run --help' for more information.
The generated command passed to DCP contains a duplicate run:
dotnet run --project /path/to/App.csproj --configuration Debug --no-launch-profile run -f net10.0-android -p:AdbTarget=-e ...
iOS equivalents (AddiOSSimulator, AddMacCatalystDevice) are unaffected. I assume Apple tooling silently ignores unrecognised trailing arguments. Android's Microsoft.Android.Run enforces strict argument parsing and hard fails.
Root Cause
MauiPlatformHelper.ConfigurePlatformResource is constrained where T : ProjectResource. Because the resource is always a ProjectResource, DCP's PrepareProjectExecutables unconditionally prepends:
projectArgs.Add("run");
projectArgs.Add("--project");
projectArgs.Add(projectMetadata.ProjectPath);
projectArgs.Add("--no-launch-profile");ConfigurePlatformResource then also appends run in its WithArgs callback:
resourceBuilder.WithArgs(context =>
{
context.Args.Add("run"); // ← redundant: DCP already added this for all ProjectResource types
context.Args.Add("-f");
context.Args.Add(platformTfm);
...
});Fix: remove context.Args.Add("run") from ConfigurePlatformResource's WithArgs callback. DCP handles it for all ProjectResource types. The -f <tfm> and remaining platform args should follow DCP's prefix directly.
Steps to Reproduce
var app = builder.AddMauiProject("my-app", "../MyApp/MyApp.csproj");
app.AddAndroidEmulator().WithReference(someService);Launch the AppHost and attempt to start the Android resource.
Expected Behaviour
dotnet run --project /path/to/App.csproj --configuration Debug --no-launch-profile -f net10.0-android -p:AdbTarget=-e ...
Actual Behaviour
dotnet run --project /path/to/App.csproj --configuration Debug --no-launch-profile run -f net10.0-android -p:AdbTarget=-e ...
Versions Affected
Aspire.Hosting.Maui 13.1.1 and 13.1.2 — MauiPlatformHelper.cs is identical in both versions.
Workaround
Until fixed, i guess we can strip the duplicate in their AppHost, it seems to be working with this workaround:
app.AddAndroidEmulator()
.WithReference(someService)
.WithArgs(ctx => ctx.Args.Remove("run"));