@@ -18,31 +18,52 @@ import { getCSharpDevKit } from '../../utils/getCSharpDevKit';
18
18
19
19
let _restoreInProgress = false ;
20
20
21
- export function registerRestoreCommands ( context : vscode . ExtensionContext , languageServer : RoslynLanguageServer ) {
22
- if ( getCSharpDevKit ( ) ) {
23
- // We do not need to register restore commands if using C# devkit.
24
- return ;
21
+ export function registerRestoreCommands (
22
+ context : vscode . ExtensionContext ,
23
+ languageServer : RoslynLanguageServer ,
24
+ csharpOutputChannel : vscode . LogOutputChannel
25
+ ) {
26
+ // We do not need to register restore commands if using C# devkit.
27
+ if ( ! getCSharpDevKit ( ) ) {
28
+ context . subscriptions . push (
29
+ vscode . commands . registerCommand ( 'dotnet.restore.project' , async ( _request ) : Promise < void > => {
30
+ return chooseProjectAndRestore ( languageServer , csharpOutputChannel ) ;
31
+ } )
32
+ ) ;
33
+ context . subscriptions . push (
34
+ vscode . commands . registerCommand ( 'dotnet.restore.all' , async ( ) : Promise < void > => {
35
+ return restore ( languageServer , csharpOutputChannel , [ ] , true ) ;
36
+ } )
37
+ ) ;
25
38
}
26
- const restoreChannel = vscode . window . createOutputChannel ( vscode . l10n . t ( '.NET NuGet Restore' ) ) ;
27
- context . subscriptions . push (
28
- vscode . commands . registerCommand ( 'dotnet.restore.project' , async ( _request ) : Promise < void > => {
29
- return chooseProjectAndRestore ( languageServer , restoreChannel ) ;
30
- } )
31
- ) ;
32
- context . subscriptions . push (
33
- vscode . commands . registerCommand ( 'dotnet.restore.all' , async ( ) : Promise < void > => {
34
- return restore ( languageServer , restoreChannel , [ ] , true ) ;
35
- } )
36
- ) ;
37
39
38
40
languageServer . registerOnRequest ( ProjectNeedsRestoreRequest . type , async ( params ) => {
39
- await restore ( languageServer , restoreChannel , params . projectFilePaths , false ) ;
41
+ let projectFilePaths = params . projectFilePaths ;
42
+ if ( getCSharpDevKit ( ) ) {
43
+ // Only restore '.cs' files (file-based apps) if CDK is loaded.
44
+ const csharpFiles = [ ] ;
45
+ for ( const path of projectFilePaths ) {
46
+ if ( path . endsWith ( '.cs' ) ) {
47
+ csharpFiles . push ( path ) ;
48
+ } else {
49
+ csharpOutputChannel . debug (
50
+ `[.NET Restore] Not restoring '${ path } ' from C# extension, because C# Dev Kit is expected to handle restore for it.`
51
+ ) ;
52
+ }
53
+ }
54
+
55
+ projectFilePaths = csharpFiles ;
56
+ }
57
+
58
+ if ( projectFilePaths . length > 0 ) {
59
+ await restore ( languageServer , csharpOutputChannel , params . projectFilePaths , false ) ;
60
+ }
40
61
} ) ;
41
62
}
42
63
43
64
async function chooseProjectAndRestore (
44
65
languageServer : RoslynLanguageServer ,
45
- restoreChannel : vscode . OutputChannel
66
+ outputChannel : vscode . LogOutputChannel
46
67
) : Promise < void > {
47
68
let projects : string [ ] ;
48
69
try {
@@ -72,12 +93,12 @@ async function chooseProjectAndRestore(
72
93
return ;
73
94
}
74
95
75
- await restore ( languageServer , restoreChannel , [ pickedItem . description ! ] , true ) ;
96
+ await restore ( languageServer , outputChannel , [ pickedItem . description ! ] , true ) ;
76
97
}
77
98
78
99
export async function restore (
79
100
languageServer : RoslynLanguageServer ,
80
- restoreChannel : vscode . OutputChannel ,
101
+ outputChannel : vscode . LogOutputChannel ,
81
102
projectFiles : string [ ] ,
82
103
showOutput : boolean
83
104
) : Promise < void > {
@@ -87,7 +108,7 @@ export async function restore(
87
108
}
88
109
_restoreInProgress = true ;
89
110
if ( showOutput ) {
90
- restoreChannel . show ( true ) ;
111
+ outputChannel . show ( true ) ;
91
112
}
92
113
93
114
const request : RestoreParams = { projectFilePaths : projectFiles } ;
@@ -101,7 +122,7 @@ export async function restore(
101
122
async ( progress , token ) => {
102
123
const writeOutput = ( output : RestorePartialResult ) => {
103
124
if ( output . message ) {
104
- restoreChannel . appendLine ( output . message ) ;
125
+ outputChannel . debug ( `[.NET Restore] ${ output . message } ` ) ;
105
126
}
106
127
107
128
progress . report ( { message : output . stage } ) ;
@@ -117,7 +138,7 @@ export async function restore(
117
138
118
139
await responsePromise . then (
119
140
( result ) => result . forEach ( ( r ) => writeOutput ( r ) ) ,
120
- ( err ) => restoreChannel . appendLine ( err )
141
+ ( err ) => outputChannel . error ( `[.NET Restore] ${ err } ` )
121
142
) ;
122
143
}
123
144
)
0 commit comments