8
8
using System . Globalization ;
9
9
using Aspire . Cli . Backchannel ;
10
10
using Aspire . Cli . Configuration ;
11
+ using Aspire . Cli . DotNet ;
11
12
using Aspire . Cli . Interaction ;
12
13
using Aspire . Cli . Projects ;
13
14
using Aspire . Cli . Resources ;
@@ -25,6 +26,7 @@ internal abstract class PublishCommandBase : BaseCommand
25
26
protected readonly IInteractionService _interactionService ;
26
27
protected readonly IProjectLocator _projectLocator ;
27
28
protected readonly AspireCliTelemetry _telemetry ;
29
+ protected readonly IDotNetSdkInstaller _sdkInstaller ;
28
30
29
31
private static bool IsCompletionStateComplete ( string completionState ) =>
30
32
completionState is CompletionStates . Completed or CompletionStates . CompletedWithWarning or CompletionStates . CompletedWithError ;
@@ -35,18 +37,20 @@ private static bool IsCompletionStateError(string completionState) =>
35
37
private static bool IsCompletionStateWarning ( string completionState ) =>
36
38
completionState == CompletionStates . CompletedWithWarning ;
37
39
38
- protected PublishCommandBase ( string name , string description , IDotNetCliRunner runner , IInteractionService interactionService , IProjectLocator projectLocator , AspireCliTelemetry telemetry , IFeatures features , ICliUpdateNotifier updateNotifier )
40
+ protected PublishCommandBase ( string name , string description , IDotNetCliRunner runner , IInteractionService interactionService , IProjectLocator projectLocator , AspireCliTelemetry telemetry , IDotNetSdkInstaller sdkInstaller , IFeatures features , ICliUpdateNotifier updateNotifier )
39
41
: base ( name , description , features , updateNotifier )
40
42
{
41
43
ArgumentNullException . ThrowIfNull ( runner ) ;
42
44
ArgumentNullException . ThrowIfNull ( interactionService ) ;
43
45
ArgumentNullException . ThrowIfNull ( projectLocator ) ;
44
46
ArgumentNullException . ThrowIfNull ( telemetry ) ;
47
+ ArgumentNullException . ThrowIfNull ( sdkInstaller ) ;
45
48
46
49
_runner = runner ;
47
50
_interactionService = interactionService ;
48
51
_projectLocator = projectLocator ;
49
52
_telemetry = telemetry ;
53
+ _sdkInstaller = sdkInstaller ;
50
54
51
55
var projectOption = new Option < FileInfo ? > ( "--project" )
52
56
{
@@ -76,6 +80,12 @@ protected PublishCommandBase(string name, string description, IDotNetCliRunner r
76
80
77
81
protected override async Task < int > ExecuteAsync ( ParseResult parseResult , CancellationToken cancellationToken )
78
82
{
83
+ // Check if the .NET SDK is available
84
+ if ( ! await SdkInstallHelper . EnsureSdkInstalledAsync ( _sdkInstaller , _interactionService , cancellationToken ) )
85
+ {
86
+ return ExitCodeConstants . SdkNotInstalled ;
87
+ }
88
+
79
89
var buildOutputCollector = new OutputCollector ( ) ;
80
90
var operationOutputCollector = new OutputCollector ( ) ;
81
91
0 commit comments