44using System . CommandLine ;
55using System . Diagnostics ;
66using Aspire . Cli . Backchannel ;
7+ using Aspire . Cli . Builds ;
78using Aspire . Cli . Certificates ;
89using Aspire . Cli . Interaction ;
910using Aspire . Cli . Projects ;
@@ -23,21 +24,24 @@ internal sealed class RunCommand : BaseCommand
2324 private readonly ICertificateService _certificateService ;
2425 private readonly IProjectLocator _projectLocator ;
2526 private readonly IAnsiConsole _ansiConsole ;
27+ private readonly IAppHostBuilder _appHostBuilder ;
2628
27- public RunCommand ( IDotNetCliRunner runner , IInteractionService interactionService , ICertificateService certificateService , IProjectLocator projectLocator , IAnsiConsole ansiConsole )
29+ public RunCommand ( IDotNetCliRunner runner , IInteractionService interactionService , ICertificateService certificateService , IProjectLocator projectLocator , IAnsiConsole ansiConsole , IAppHostBuilder appHostBuilder )
2830 : base ( "run" , "Run an Aspire app host in development mode." )
2931 {
3032 ArgumentNullException . ThrowIfNull ( runner ) ;
3133 ArgumentNullException . ThrowIfNull ( interactionService ) ;
3234 ArgumentNullException . ThrowIfNull ( certificateService ) ;
3335 ArgumentNullException . ThrowIfNull ( projectLocator ) ;
3436 ArgumentNullException . ThrowIfNull ( ansiConsole ) ;
37+ ArgumentNullException . ThrowIfNull ( appHostBuilder ) ;
3538
3639 _runner = runner ;
3740 _interactionService = interactionService ;
3841 _certificateService = certificateService ;
3942 _projectLocator = projectLocator ;
4043 _ansiConsole = ansiConsole ;
44+ _appHostBuilder = appHostBuilder ;
4145
4246 var projectOption = new Option < FileInfo ? > ( "--project" ) ;
4347 projectOption . Description = "The path to the Aspire app host project file." ;
@@ -46,6 +50,10 @@ public RunCommand(IDotNetCliRunner runner, IInteractionService interactionServic
4650 var watchOption = new Option < bool > ( "--watch" , "-w" ) ;
4751 watchOption . Description = "Start project resources in watch mode." ;
4852 Options . Add ( watchOption ) ;
53+
54+ var noCacheOption = new Option < bool > ( "--no-cache" , "-nc" ) ;
55+ noCacheOption . Description = "Do not use cached build of the app host." ;
56+ Options . Add ( noCacheOption ) ;
4957 }
5058
5159 protected override async Task < int > ExecuteAsync ( ParseResult parseResult , CancellationToken cancellationToken )
@@ -89,13 +97,15 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
8997
9098 if ( ! watch )
9199 {
100+ var useCache = ! parseResult . GetValue < bool > ( "--no-cache" ) ;
101+
92102 var buildOptions = new DotNetCliRunnerInvocationOptions
93103 {
94104 StandardOutputCallback = outputCollector . AppendOutput ,
95105 StandardErrorCallback = outputCollector . AppendError ,
96106 } ;
97107
98- var buildExitCode = await AppHostHelper . BuildAppHostAsync ( _runner , _interactionService , effectiveAppHostProjectFile , buildOptions , cancellationToken ) ;
108+ var buildExitCode = await AppHostHelper . BuildAppHostAsync ( _appHostBuilder , useCache , _interactionService , effectiveAppHostProjectFile , buildOptions , cancellationToken ) ;
99109
100110 if ( buildExitCode != 0 )
101111 {
0 commit comments