@@ -18,31 +18,52 @@ import { getCSharpDevKit } from '../../utils/getCSharpDevKit';
1818
1919let _restoreInProgress = false ;
2020
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+ ) ;
2538 }
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- ) ;
3739
3840 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+ }
4061 } ) ;
4162}
4263
4364async function chooseProjectAndRestore (
4465 languageServer : RoslynLanguageServer ,
45- restoreChannel : vscode . OutputChannel
66+ outputChannel : vscode . LogOutputChannel
4667) : Promise < void > {
4768 let projects : string [ ] ;
4869 try {
@@ -72,12 +93,12 @@ async function chooseProjectAndRestore(
7293 return ;
7394 }
7495
75- await restore ( languageServer , restoreChannel , [ pickedItem . description ! ] , true ) ;
96+ await restore ( languageServer , outputChannel , [ pickedItem . description ! ] , true ) ;
7697}
7798
7899export async function restore (
79100 languageServer : RoslynLanguageServer ,
80- restoreChannel : vscode . OutputChannel ,
101+ outputChannel : vscode . LogOutputChannel ,
81102 projectFiles : string [ ] ,
82103 showOutput : boolean
83104) : Promise < void > {
@@ -87,7 +108,7 @@ export async function restore(
87108 }
88109 _restoreInProgress = true ;
89110 if ( showOutput ) {
90- restoreChannel . show ( true ) ;
111+ outputChannel . show ( true ) ;
91112 }
92113
93114 const request : RestoreParams = { projectFilePaths : projectFiles } ;
@@ -101,7 +122,7 @@ export async function restore(
101122 async ( progress , token ) => {
102123 const writeOutput = ( output : RestorePartialResult ) => {
103124 if ( output . message ) {
104- restoreChannel . appendLine ( output . message ) ;
125+ outputChannel . debug ( `[.NET Restore] ${ output . message } ` ) ;
105126 }
106127
107128 progress . report ( { message : output . stage } ) ;
@@ -117,7 +138,7 @@ export async function restore(
117138
118139 await responsePromise . then (
119140 ( result ) => result . forEach ( ( r ) => writeOutput ( r ) ) ,
120- ( err ) => restoreChannel . appendLine ( err )
141+ ( err ) => outputChannel . error ( `[.NET Restore] ${ err } ` )
121142 ) ;
122143 }
123144 )
0 commit comments