Skip to content

feat(aspire): give the heads a dev server for Hot Reload - #3317

Draft
Kunal22shah wants to merge 2 commits into
dev/ks/aspire-bakingfrom
dev/ks/aspire-devserver
Draft

Kunal22shah wants to merge 2 commits into
dev/ks/aspire-bakingfrom
dev/ks/aspire-devserver

Conversation

@Kunal22shah

Copy link
Copy Markdown
Contributor

Stack 4 of 4. Based on #3311 (baking the environment), #3310 (AppHost package) and #3309 (client package).

PR Type

  • Feature

What is the current behavior?

A head started by the AppHost gets Hot Reload only when an IDE, or a dotnet dnx -y uno.devserver start run by hand, already provides a dev server for the solution. From a terminal, the head logs "DevServer endpoint has no port" and never connects.

What is the new behavior?

Every head gets a dev server, with or without an IDE. The uno.devserver CLI does the work; the AppHost runs it and reads the result.

  • Reuse or start. Before any resource starts, the AppHost runs the CLI's start with itself as the parent process. The CLI reuses the dev server already running for the solution, an IDE's for example, so the IDE's tools see the heads. Otherwise it starts one that stops on its own once the AppHost is gone and removes its registration. The AppHost never stops a dev server itself.
  • Matching version. The CLI is the version of the Uno.WinUI.DevServer package the app restores, which the Uno.Sdk chooses. The AppHost restores the app first, under its build lock, and reads the version from the assets file.
  • Port. Each head's build gets -p:UnoRemoteControlPort=<port>, the property an IDE sets through .csproj.user, so desktop, WebAssembly and Android heads all connect.
  • Dashboard. The uno-devserver resource, one per solution: Running with its port, process and who started it; Unavailable or FailedToStart with the reason and how to turn it off; Exited if it stops during the run. A head shows Waiting for dev server until the port is known.
  • Off switch. Uno__DevServer__Enabled=false in the AppHost's environment, or "Uno": { "DevServer": { "Enabled": false } } in its settings: no dev server is added and heads build as before. The docs say the dev server accepts connections from the network, as one an IDE starts does.

No public API is added.

Scope and limits

  • The dev server here is for Hot Reload only, and optional: when it is unavailable or turned off, the heads build and run without Hot Reload, nothing else changes.
  • A reused dev server, started by an IDE, is used as it is: anything delivered through a dev server add-in later cannot rely on it being there.
  • An IDE opened after the AppHost starts a dev server of its own; the heads keep the AppHost's for that run.
  • Once the CLI exits, the dev server's later log lines are not in the dashboard.

Important

Question for the dev server maintainers: should an Aspire integration start the dev server through the uno.devserver CLI, or should the Uno.Sdk or the CLI own this? The answer decides whether the reuse rules, the off switch and the failure handling belong in this repository. Draft until it is answered, and not to be merged before #3309-#3311.

Reviewer's guide

  • Start with the spec's Hot Reload section.
  • Code: UnoDevServer.cs (resource, start, discovery, watch), then HeadBuild.cs (waiting for the port, the build property) and DotnetCommand.cs (the process helper, now shared with the head build).
  • Tests: Given_UnoDevServer (discovery parsing, version check, setting, one dev server per solution, the unavailable path through a real restore), Given_HeadBuild (the port reaching a real build, the waiting state), Given_DotnetCommand (timeouts, a child keeping the output open).
  • The last commit is docs only: the spec and the how-to.

Verification

On a generated -preset recommended -server -aspire app with desktop and WebAssembly heads, never built before, with no IDE open:

  • The AppHost restored the app, the CLI started the dev server, and both heads connected.
  • XAML edits reached the desktop window and the browser without a restart.
  • With only the AppHost ended, the dev server stopped within seconds and removed its registration.
  • With a dev server already running for the solution, the heads used it, and it kept running after the AppHost stopped.
  • With the setting off, no dev server was added and the desktop head started without waiting.

Not verified: the Android head, macOS and Linux, a Visual Studio or Rider session, an offline machine.

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

🤖 Generated with Claude Code

- Run the uno.devserver CLI of the app's dev server version: it reuses the one running for the solution, an IDE's for example, or starts one that stops with the AppHost

- Pass its port to each head's build as UnoRemoteControlPort

- Show it as the uno-devserver resource, one per solution; Uno:DevServer:Enabled=false turns it off
Comment on lines +432 to +435
catch (Exception exception)
{
logger.LogDebug(exception, "The state of the dev server could not be published.");
}
var recognized = true;
while (elapsed.Elapsed < RegistrationTimeout)
{
var output = new StringBuilder();
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