Skip to content

fix(aspire): build a head only once its dependencies are ready - #3320

Open
Kunal22shah wants to merge 2 commits into
mainfrom
dev/ks/aspire-build-after-dependencies
Open

Kunal22shah wants to merge 2 commits into
mainfrom
dev/ks/aspire-build-after-dependencies

Conversation

@Kunal22shah

Copy link
Copy Markdown
Contributor

Related to #3309. Follows #3310, independent of the open Aspire PRs.

PR Type

  • Bugfix

What is the current behavior?

On a first build, an app from dotnet new unoapp -preset recommended -server -aspire can fail to start: the AppHost builds the app's head at the same moment Aspire builds the server, both build the shared *.DataContracts project, and one fails with CS2012 ("Cannot open ... DataContracts.dll for writing"). Depending on which build loses, the API or the head ends up FailedToStart. Warm builds usually escape it.

The head's build runs in OnBeforeResourceStarted, which Aspire raises before it processes the head's WaitFor dependencies.

What is the new behavior?

Before building, the head waits for the resources it waits for (WaitFor, WaitForStart) to be ready, through Aspire's ResourceNotificationService.WaitForDependenciesAsync. It shows Waiting meanwhile, as any Aspire resource does. Aspire's own build of the server is finished by then, so the shared project is built once at a time.

A head that shares a project with a resource it does not wait for can still collide; the template waits for the API on every head.

Reviewer's guide

  • The fix is the hook in UnoProjectBuilderExtensions.cs.
  • Test: Given_HeadBuild.When_HeadWaitsForAResource_Then_ItBuildsOnlyOnceThatResourceRuns fails without the fix (the head never reaches Waiting) and passes with it.
  • The second commit is docs only: one bullet in the spec.

Verification

  • Uno.Extensions.Aspire.Hosting.Tests: 32 passed.
  • A generated sample with desktop, WebAssembly and Android heads, run from a copy with no bin or obj folder: the first run failed with CS2012 on Flow.DataContracts.dll and the API never started; with the fix, the API and every head started and the heads reached the API.

PR Checklist

  • Tested code with current supported SDKs
  • Docs have been added/updated (spec)
  • Unit tests for the changes have been added
  • Contains NO breaking changes
  • Associated with an issue

🤖 Generated with Claude Code

@Kunal22shah
Kunal22shah marked this pull request as ready for review November 28, 2026 17:12
@Kunal22shah Kunal22shah self-assigned this Nov 28, 2026
@mergify

mergify Bot commented Nov 28, 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 once it meets the queue conditions

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.

1 participant