diff --git a/src/Aspire.Cli/Commands/RunCommand.cs b/src/Aspire.Cli/Commands/RunCommand.cs index 4cf26e72d2c..6cce7664566 100644 --- a/src/Aspire.Cli/Commands/RunCommand.cs +++ b/src/Aspire.Cli/Commands/RunCommand.cs @@ -74,21 +74,24 @@ protected override async Task ExecuteAsync(ParseResult parseResult, Cancell return ExitCodeConstants.FailedToTrustCertificates; } - appHostCompatabilityCheck = await AppHostHelper.CheckAppHostCompatabilityAsync(_runner, effectiveAppHostProjectFile, cancellationToken); + var watch = parseResult.GetValue("--watch"); - if (!appHostCompatabilityCheck?.IsCompatableAppHost ?? throw new InvalidOperationException("IsCompatableAppHost is null")) + if (!watch) { - return ExitCodeConstants.FailedToDotnetRunAppHost; - } - - var watch = parseResult.GetValue("--watch"); + var buildExitCode = await AppHostHelper.BuildAppHostAsync(_runner, effectiveAppHostProjectFile, cancellationToken); - 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; + } + } + + appHostCompatabilityCheck = await AppHostHelper.CheckAppHostCompatabilityAsync(_runner, effectiveAppHostProjectFile, cancellationToken); - if (buildExitCode != 0) + if (!appHostCompatabilityCheck?.IsCompatableAppHost ?? throw new InvalidOperationException("IsCompatableAppHost is null")) { - AnsiConsole.MarkupLine($"[red bold]:thumbs_down: The project could not be built. For more information run with --debug switch.[/]"); - return ExitCodeConstants.FailedToBuildArtifacts; + return ExitCodeConstants.FailedToDotnetRunAppHost; } var backchannelCompletitionSource = new TaskCompletionSource(); @@ -96,7 +99,7 @@ protected override async Task ExecuteAsync(ParseResult parseResult, Cancell var pendingRun = _runner.RunAsync( effectiveAppHostProjectFile, watch, - true, + !watch, Array.Empty(), env, backchannelCompletitionSource, diff --git a/src/Aspire.Cli/DotNetCliRunner.cs b/src/Aspire.Cli/DotNetCliRunner.cs index 3e12e70adf4..e8d947d1f12 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";