Fix aspire run hang when defaultWatchEnabled and build fails#16702
Open
Bertolossi wants to merge 2 commits intomicrosoft:mainfrom
Open
Fix aspire run hang when defaultWatchEnabled and build fails#16702Bertolossi wants to merge 2 commits intomicrosoft:mainfrom
Bertolossi wants to merge 2 commits intomicrosoft:mainfrom
Conversation
When DefaultWatchEnabled was set, the CLI skipped its pre-build and relied on dotnet watch, which idles instead of exiting on build errors. Always pre-build in the CLI so build failures surface and short-circuit to FailedToBuildArtifacts. Fixes microsoft#13142 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16702Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16702" |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR ensures the run command exits with a build-failure code (and does not start the AppHost) when default watch mode is enabled and the initial build fails.
Changes:
- Added a regression test asserting build failures in default watch mode return
FailedToBuildArtifactsand do not invoke AppHost run. - Changed AppHost project execution to perform the initial build even when watch mode is enabled.
- Updated inline comments describing
noBuildbehavior for watch vs non-watch runs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/Aspire.Cli.Tests/Commands/RunCommandTests.cs | Adds coverage for watch-default behavior when the initial build fails. |
| src/Aspire.Cli/Projects/DotNetAppHostProject.cs | Builds even in watch mode to fail fast before starting AppHost; updates comments around noBuild. |
Author
|
@microsoft-github-policy-service agree |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a hang in
aspire runwhen thedefaultWatchEnabledfeature flag is set and the AppHost has a build error.Repro: With the following in
.aspire/settings.json:introduce any compile error in the solution and run
aspire run. The CLI hangs indefinitely at "Connecting to apphost..." and must be killed manually.Root cause: In
DotNetAppHostProject.RunAsync, the CLI's pre-build step was gated on!watch. In watch mode the CLI delegated building entirely todotnet watch, which by design does not exit on a build error — it idles waiting for a file change. The CLI then sits onBackchannelCompletionSourceforever because the AppHost never starts.Fix: Drop the
!watchcondition so the CLI always performs an explicit pre-build (whenshouldBuildInCli). On failure, the existing path setsOutputCollector, signalsBuildCompletionSource(false), and returnsExitCodeConstants.FailedToBuildArtifacts, so build errors are surfaced to the user and the process exits cleanly. After a successful pre-build, watch mode still passesnoBuild: falsetodotnet watch runso it can manage its own incremental builds and hot reload.A regression test (
RunCommand_WhenDefaultWatchEnabledFeatureFlagIsTrueAndBuildFails_ReturnsBuildFailure) was added inRunCommandTeststo lock the behavior in.No new dependencies.
Fixes #13142
Checklist
<remarks />and<code />elements on your triple slash comments?aspire.devissue: