Skip to content

feat(aspire): run an Uno app's heads from an Aspire AppHost - #3310

Open
Kunal22shah wants to merge 9 commits into
dev/ks/aspire-supportfrom
dev/ks/aspire-apphost
Open

Kunal22shah wants to merge 9 commits into
dev/ks/aspire-supportfrom
dev/ks/aspire-apphost

Conversation

@Kunal22shah

@Kunal22shah Kunal22shah commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Stack 2 of 3. Based on #3309 (client package); next: #3311 (baking the environment).

PR Type

  • Feature

What is the current behavior?

Aspire's AddProject rejects an Uno app ("Your project targets multiple frameworks"), so each head has to be wired by hand as an AddExecutable running dotnet run -f <tfm>.

What is the new behavior?

A new package for the AppHost, Uno.Extensions.Aspire.Hosting, marked experimental (UNOASPIRE001, on each method, since a call to an extension method does not report the attribute of its class). The names follow Aspire's MAUI integration (AddMauiProject). It needs Aspire 13.6.5 or later and is tested with 13.6.5 and 17:

var app = builder.AddUnoProject("app", "../MyApp/MyApp.csproj");

app.AddDesktop().WithReference(api).WaitFor(api);
app.AddWebAssembly().WithReference(api).WaitFor(api);
app.AddAndroidEmulator().WithReference(api).WaitFor(api);
  • Each head is a resource in the dashboard. Before it starts, it is built under a lock held per app, shown as Queued then Building, since heads share the project's obj folder; it then runs dotnet run -f <tfm> --no-build --no-launch-profile, with Hot Reload enabled.
  • The target framework comes from the project file, versioned platforms such as net10.0-android36.0 included; a start fails with a clear message when the project does not target it.
  • Arguments given with WithArgs that change the build (properties, configuration, runtime) reach the build too, not only dotnet run --no-build.
  • Each head runs in the Development environment, as Aspire's own projects do.
  • Desktop starts with the AppHost and gets the API address and telemetry like any process.
  • WebAssembly is served on an endpoint the AppHost owns, with a health check.
  • Android deploys to the running emulator (-p:AdbTarget=-e).
  • WebAssembly and Android start from the dashboard, not with the AppHost, so the heads don't build the same project at once.
  • Stopping a head ends its app.

In this PR the WebAssembly and Android apps run but don't know the API's address yet: a browser and an Android app don't see the environment Aspire sets. The next PR adds that.

Reviewer's guide

Verified on the sample: the desktop head started once the API was healthy and reached the API and the database; stopping the head or the AppHost ended the app.

PR Checklist

  • Tested code with current supported SDKs
  • Docs have been added/updated
  • Unit Tests and/or UI Tests for the changes have been added
  • Wasm UI Tests are not showing unexpected differences
  • Contains NO breaking changes
  • Updated the Release Notes
  • Associated with an issue

Other information

Not verified yet: stopping a head on macOS and Linux.

🤖 Generated with Claude Code

@Kunal22shah
Kunal22shah force-pushed the dev/ks/aspire-apphost branch from 483e9e9 to e4e79c0 Compare November 18, 2026 19:33
@Kunal22shah
Kunal22shah marked this pull request as ready for review November 18, 2026 19:42
@mergify

mergify Bot commented Nov 18, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

@Kunal22shah
Kunal22shah force-pushed the dev/ks/aspire-apphost branch from e4e79c0 to 4f8cc5a Compare November 18, 2026 20:01

@carldebilly carldebilly left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shape of the AppHost API is right: AddUnoApp(name, csproj) plus one method per head mirrors AddMauiProject plus AddAndroidEmulator() in Aspire.Hosting.Maui, including explicit start, -p:AdbTarget=-e, no ProjectReference from the AppHost, and a logical parent that is not registered in the model (MAUI does the same, so it stays out of the dashboard).

The one change I would make before this ships as more than experimental is build serialization (inline). The overall review of the stack is on #3309.

Nits:

  • Uno.Extensions.Aspire.Hosting.Tests.csproj: a short XML comment on the UNOASPIRE001 NoWarn saying the tests exercise the experimental API on purpose.
  • TestSolution.StartAsync resolves the execution configuration without starting anything, and duplicates Given_UnoApp.ResolveAsync; one helper named after what it does (e.g. ResolveExecutionConfigurationAsync) would serve both, with the #3311 call sites renamed.

@Kunal22shah
Kunal22shah force-pushed the dev/ks/aspire-apphost branch from 4f8cc5a to c4949dc Compare November 18, 2026 20:58

@kazo0 kazo0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging:

  • CI has not run on this PR or on #3311. The Azure pipeline is skipped because the base isn't main, so the Hosting package and its tests have never run on an agent. They start real dotnet build and MSBuild processes, which is where agents differ most. Please queue the pipeline on dev/ks/aspire-baking. Locally, the Hosting tests pass (52/52, Release).
  • The description says the heads run "with Hot Reload enabled". The spec says Hot Reload also needs a running dev server; please align the description.

Comment thread src/Directory.Packages.props Resolved
@Kunal22shah
Kunal22shah force-pushed the dev/ks/aspire-apphost branch from c4949dc to c995bcd Compare November 19, 2026 17:04
@kazo0

kazo0 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

macOS validation: AppHost heads

Packages 255.255.255.255-aspire.1 built from dev/ks/aspire-baking @ a312556 (the same bits as the Windows run). Environment: macOS (Darwin 27.2, arm64), .NET SDK 10.0.403, Xcode 27.1, AppHost SDK 13.6.5, Aspire CLI 13.6.4 (check 8 repeated with 17.0.0).

Everything matches the Windows baseline, including stopping a head on macOS, which the PRs listed as unverified. There's one non-blocking finding on check 8.

# Check Result
8 Desktop waits for the API ⚠️ The launch waits; the build doesn't (see below)
2 Aspire's address wins over settings ✅ ping GET https = 1 despite localhost:1 in settings
4 Retries under the AppHost ✅ flaky GET https = 4, flaky POST https = 1
5 Telemetry in the dashboard ✅ GET/POST spans and HTTP logs in aspire otel
11 WithArgs reaches the build ✅ from-withargs
13 Stopping a head on macOS ✅ After aspire resource app-desktop stop, both the dotnet run wrapper and the app process are gone; the resource shows Finished
12 WebAssembly is served ✅ 200, Healthy
9 Heads build one at a time ✅ Waiting for another head of 'app' to finish building., then the wasm build starts after desktop's ends
10 Framework the app doesn't target ✅ 'app-badtfm' runs net10.0-maccatalyst, which the project does not target (net10.0-android, net10.0-browserwasm, net10.0-desktop, net10.0-ios). Set another one with WithTargetFramework.
14 Hot Reload ✅ a XAML edit and a C# edit both applied to the running window, same PID

Android (23–25) wasn't run on the Mac.

Finding (non-blocking): a head shows "Building" while it waits for its dependency

The head's build doesn't wait for the WaitFor dependency; only the app launch does. That's fine in itself, since the build doesn't need the API running and the addresses are allocated up front (the browser check on #3311 passes). But while the head waits, its state stays Building, so the dashboard and aspire describe say "Building" for a head whose build has already finished.

Clean start (AppHost log):

19:21:56.267  app-desktop  Starting -> Building
19:21:56.374  api          Running   (ready at .388; api has no health checks)
19:22:03.047  app-desktop  build finished
19:22:03.106  app-desktop  Waiting for resource 'api' to enter the 'Running' state.
19:22:03.121  app-desktop  process starts, Running

With api stopped, aspire resource app-desktop start builds the head (finished 19:22:21), logs Waiting for resource 'api' to enter the 'Running' state. and launches nothing. describe shows app-desktop: Building for as long as it waits. Starting api again lets the head launch. The result is the same with Aspire CLI 13.6.4 and 17.0.0.

Suggestion: switch the state to a waiting state (as Aspire's own resources do) once the build has finished, or document that heads build in parallel with their dependencies. If the build was meant to wait, then this is a bug instead.

…o app from the AppHost

- AddUnoApp, AddDesktop, AddWebAssembly, AddAndroidEmulator, WithTargetFramework, WithLaunchProfile
- heads run dotnet run without a launch profile, with Hot Reload enabled
- the WebAssembly head is served on an endpoint the AppHost owns and health-checked
- the Android head deploys to the running emulator; both are started by hand
…framework

- a head builds under the app's build lock before it starts, shown as Queued then Building,
  then runs with dotnet run --no-build; its build output goes to its log
- the target framework comes from the project file; a start fails with a clear message
  when the project does not target it
- the project folder is computed once on UnoAppResource
- tests share one helper to resolve a head's run configuration
- -p:, --property: and -c given with WithArgs reach dotnet build, not only dotnet run --no-build
- a build that exits as it times out keeps the timeout message
- the app exports telemetry only in Development, and an app without UseEnvironment would get Production
- Follows Aspire's AddMauiProject and MauiProjectResource

- UnoAppResource is UnoProjectResource, and a head's App property is Project
- A call to an extension method does not report the attribute of its class
@Kunal22shah
Kunal22shah force-pushed the dev/ks/aspire-apphost branch from c995bcd to 6249ce8 Compare November 25, 2026 18:54
.WithArgs(context => AddRunArguments(head, context.Args))
.WithHttpEndpoint(name: UnoWebAssemblyResource.EndpointName)
.WithEnvironment(context => context.EnvironmentVariables[ServerUrlsVariable] =
ReferenceExpression.Create($"http://localhost:{head.GetEndpoint(UnoWebAssemblyResource.EndpointName).Property(EndpointProperty.TargetPort)}"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants