Skip to content

Commit 8489a32

Browse files
authored
Fix --watch hangs. (#8585)
* Fix --watch hangs. * Don't prebuild in watch mode. * Fix up merge.
1 parent a98ccc2 commit 8489a32

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/Aspire.Cli/Commands/RunCommand.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,32 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
7474
return ExitCodeConstants.FailedToTrustCertificates;
7575
}
7676

77-
appHostCompatabilityCheck = await AppHostHelper.CheckAppHostCompatabilityAsync(_runner, effectiveAppHostProjectFile, cancellationToken);
77+
var watch = parseResult.GetValue<bool>("--watch");
7878

79-
if (!appHostCompatabilityCheck?.IsCompatableAppHost ?? throw new InvalidOperationException("IsCompatableAppHost is null"))
79+
if (!watch)
8080
{
81-
return ExitCodeConstants.FailedToDotnetRunAppHost;
82-
}
83-
84-
var watch = parseResult.GetValue<bool>("--watch");
81+
var buildExitCode = await AppHostHelper.BuildAppHostAsync(_runner, effectiveAppHostProjectFile, cancellationToken);
8582

86-
var buildExitCode = await AppHostHelper.BuildAppHostAsync(_runner, effectiveAppHostProjectFile, cancellationToken);
83+
if (buildExitCode != 0)
84+
{
85+
AnsiConsole.MarkupLine($"[red bold]:thumbs_down: The project could not be built. For more information run with --debug switch.[/]");
86+
return ExitCodeConstants.FailedToBuildArtifacts;
87+
}
88+
}
89+
90+
appHostCompatabilityCheck = await AppHostHelper.CheckAppHostCompatabilityAsync(_runner, effectiveAppHostProjectFile, cancellationToken);
8791

88-
if (buildExitCode != 0)
92+
if (!appHostCompatabilityCheck?.IsCompatableAppHost ?? throw new InvalidOperationException("IsCompatableAppHost is null"))
8993
{
90-
AnsiConsole.MarkupLine($"[red bold]:thumbs_down: The project could not be built. For more information run with --debug switch.[/]");
91-
return ExitCodeConstants.FailedToBuildArtifacts;
94+
return ExitCodeConstants.FailedToDotnetRunAppHost;
9295
}
9396

9497
var backchannelCompletitionSource = new TaskCompletionSource<AppHostBackchannel>();
9598

9699
var pendingRun = _runner.RunAsync(
97100
effectiveAppHostProjectFile,
98101
watch,
99-
true,
102+
!watch,
100103
Array.Empty<string>(),
101104
env,
102105
backchannelCompletitionSource,

src/Aspire.Cli/DotNetCliRunner.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ public async Task<int> RunAsync(FileInfo projectFile, bool watch, bool noBuild,
126126

127127
if (watch && noBuild)
128128
{
129-
throw new InvalidOperationException("Cannot use --watch and --no-build at the same time.");
129+
var ex = new InvalidOperationException("Cannot use --watch and --no-build at the same time.");
130+
backchannelCompletionSource?.SetException(ex);
131+
throw ex;
130132
}
131133

132134
var watchOrRunCommand = watch ? "watch" : "run";

0 commit comments

Comments
 (0)