From 5859fc473ead1aaa07b8ec614e41cdd1f6de0b6f Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Mon, 7 Apr 2025 13:34:04 +0000 Subject: [PATCH 1/3] Fix --watch hangs. --- src/Aspire.Cli/Commands/RunCommand.cs | 2 +- src/Aspire.Cli/DotNetCliRunner.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Aspire.Cli/Commands/RunCommand.cs b/src/Aspire.Cli/Commands/RunCommand.cs index b7d9b1e70c1..3e5b499aad7 100644 --- a/src/Aspire.Cli/Commands/RunCommand.cs +++ b/src/Aspire.Cli/Commands/RunCommand.cs @@ -93,7 +93,7 @@ protected override async Task ExecuteAsync(ParseResult parseResult, Cancell var pendingRun = _runner.RunAsync( effectiveAppHostProjectFile, watch, - true, + !watch, // If we aren't in watch mode we can no-build here, but watch doesn't support no-build. Array.Empty(), env, backchannelCompletitionSource, diff --git a/src/Aspire.Cli/DotNetCliRunner.cs b/src/Aspire.Cli/DotNetCliRunner.cs index 7833fedf452..03e487f44f7 100644 --- a/src/Aspire.Cli/DotNetCliRunner.cs +++ b/src/Aspire.Cli/DotNetCliRunner.cs @@ -126,7 +126,9 @@ public async Task RunAsync(FileInfo projectFile, bool watch, bool noBuild, if (watch && noBuild) { - throw new InvalidOperationException("Cannot use --watch and --no-build at the same time."); + var ex = new InvalidOperationException("Cannot use --watch and --no-build at the same time."); + backchannelCompletionSource?.SetException(ex); + throw ex; } var watchOrRunCommand = watch ? "watch" : "run"; From 5f87e7b2630fccba7f6cce995fe7f20ae06f9fd6 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Mon, 7 Apr 2025 13:38:24 +0000 Subject: [PATCH 2/3] Don't prebuild in watch mode. --- src/Aspire.Cli/Commands/RunCommand.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Aspire.Cli/Commands/RunCommand.cs b/src/Aspire.Cli/Commands/RunCommand.cs index 3e5b499aad7..96560c09769 100644 --- a/src/Aspire.Cli/Commands/RunCommand.cs +++ b/src/Aspire.Cli/Commands/RunCommand.cs @@ -80,12 +80,15 @@ protected override async Task ExecuteAsync(ParseResult parseResult, Cancell var watch = parseResult.GetValue("--watch"); - var buildExitCode = await AppHostHelper.BuildAppHostAsync(_runner, effectiveAppHostProjectFile, cancellationToken); - - if (buildExitCode != 0) + if (!watch) { - AnsiConsole.MarkupLine($"[red bold]:thumbs_down: The project could not be built. For more information run with --debug switch.[/]"); - return ExitCodeConstants.FailedToBuildArtifacts; + var buildExitCode = await AppHostHelper.BuildAppHostAsync(_runner, effectiveAppHostProjectFile, cancellationToken); + + if (buildExitCode != 0) + { + AnsiConsole.MarkupLine($"[red bold]:thumbs_down: The project could not be built. For more information run with --debug switch.[/]"); + return ExitCodeConstants.FailedToBuildArtifacts; + } } var backchannelCompletitionSource = new TaskCompletionSource(); From ee14ad5dd8b1c87c1504530f49c151884b3dd529 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Mon, 7 Apr 2025 21:39:27 +0000 Subject: [PATCH 3/3] Fix up merge. --- src/Aspire.Cli/Commands/RunCommand.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Aspire.Cli/Commands/RunCommand.cs b/src/Aspire.Cli/Commands/RunCommand.cs index 6897031fb34..6cce7664566 100644 --- a/src/Aspire.Cli/Commands/RunCommand.cs +++ b/src/Aspire.Cli/Commands/RunCommand.cs @@ -75,6 +75,7 @@ protected override async Task ExecuteAsync(ParseResult parseResult, Cancell } var watch = parseResult.GetValue("--watch"); + if (!watch) { var buildExitCode = await AppHostHelper.BuildAppHostAsync(_runner, effectiveAppHostProjectFile, cancellationToken); @@ -93,14 +94,6 @@ protected override async Task ExecuteAsync(ParseResult parseResult, Cancell return ExitCodeConstants.FailedToDotnetRunAppHost; } - var buildExitCode = await AppHostHelper.BuildAppHostAsync(_runner, effectiveAppHostProjectFile, cancellationToken); - - if (buildExitCode != 0) - { - AnsiConsole.MarkupLine($"[red bold]:thumbs_down: The project could not be built. For more information run with --debug switch.[/]"); - return ExitCodeConstants.FailedToBuildArtifacts; - } - var backchannelCompletitionSource = new TaskCompletionSource(); var pendingRun = _runner.RunAsync(