@@ -24,6 +24,7 @@ import {
24
24
nugetTempPath ,
25
25
rootPath ,
26
26
devKitDependenciesDirectory ,
27
+ xamlDesignToolsDirectory ,
27
28
} from '../tasks/projectPaths' ;
28
29
import { getPackageJSON } from '../tasks/packageJson' ;
29
30
import { createPackageAsync } from '../tasks/vsceTasks' ;
@@ -56,6 +57,35 @@ export const platformSpecificPackages: VSIXPlatformInfo[] = [
56
57
{ vsceTarget : 'darwin-arm64' , rid : 'osx-arm64' , platformInfo : new PlatformInformation ( 'darwin' , 'arm64' ) } ,
57
58
] ;
58
59
60
+ interface NugetPackageInfo {
61
+ getPackageName : ( platformInfo : VSIXPlatformInfo | undefined ) => string ;
62
+ packageJsonName : string ;
63
+ getPackageContentPath : ( platformInfo : VSIXPlatformInfo | undefined ) => string ;
64
+ vsixOutputPath : string ;
65
+ }
66
+
67
+ // Set of NuGet packages that we need to download and install.
68
+ export const nugetPackageInfo : { [ key : string ] : NugetPackageInfo } = {
69
+ roslyn : {
70
+ getPackageName : ( platformInfo ) => `Microsoft.CodeAnalysis.LanguageServer.${ platformInfo ?. rid ?? 'neutral' } ` ,
71
+ packageJsonName : 'roslyn' ,
72
+ getPackageContentPath : ( platformInfo ) => path . join ( 'content' , 'LanguageServer' , platformInfo ?. rid ?? 'neutral' ) ,
73
+ vsixOutputPath : languageServerDirectory ,
74
+ } ,
75
+ roslynDevKit : {
76
+ getPackageName : ( _platformInfo ) => 'Microsoft.VisualStudio.LanguageServices.DevKit' ,
77
+ packageJsonName : 'roslyn' ,
78
+ getPackageContentPath : ( _platformInfo ) => 'content' ,
79
+ vsixOutputPath : devKitDependenciesDirectory ,
80
+ } ,
81
+ xamlDesignTools : {
82
+ getPackageName : ( _platformInfo ) => 'Microsoft.VisualStudio.DesignToolsBase' ,
83
+ packageJsonName : 'xamlDesignTools' ,
84
+ getPackageContentPath : ( _platformInfo ) => '' ,
85
+ vsixOutputPath : xamlDesignToolsDirectory ,
86
+ } ,
87
+ } ;
88
+
59
89
const vsixTasks : string [ ] = [ ] ;
60
90
for ( const p of platformSpecificPackages ) {
61
91
let platformName : string ;
@@ -100,11 +130,12 @@ gulp.task('installDependencies', async () => {
100
130
const packageJSON = getPackageJSON ( ) ;
101
131
102
132
const platform = await PlatformInformation . GetCurrent ( ) ;
133
+ const vsixPlatformInfo = platformSpecificPackages . find (
134
+ ( p ) => p . platformInfo . platform === platform . platform && p . platformInfo . architecture === platform . architecture
135
+ ) ! ;
103
136
104
137
try {
105
- await installRoslyn ( packageJSON , platform ) ;
106
- await installDebugger ( packageJSON , platform ) ;
107
- await installRazor ( packageJSON , platform ) ;
138
+ acquireAndInstallAllNugetPackages ( vsixPlatformInfo , packageJSON , true ) ;
108
139
} catch ( err ) {
109
140
const message = ( err instanceof Error ? err . stack : err ) ?? '<unknown error>' ;
110
141
// NOTE: Extra `\n---` at the end is because gulp will print this message following by the
@@ -113,52 +144,75 @@ gulp.task('installDependencies', async () => {
113
144
}
114
145
} ) ;
115
146
147
+ // Defines a special task to acquire all the platform specific Roslyn packages.
148
+ // All packages need to be saved to the consumption AzDo artifacts feed, for non-platform
149
+ // specific packages this only requires running the installDependencies tasks. However for Roslyn packages
150
+ // we need to acquire the nuget packages once for each platform to ensure they get saved to the feed.
116
151
gulp . task (
117
152
'updateRoslynVersion' ,
118
153
// Run the fetch of all packages, and then also installDependencies after
119
154
gulp . series ( async ( ) => {
120
155
const packageJSON = getPackageJSON ( ) ;
121
156
122
157
// Fetch the neutral package that we don't otherwise have in our platform list
123
- await acquireRoslyn ( packageJSON , undefined , true ) ;
158
+ await acquireNugetPackage ( nugetPackageInfo . roslyn , undefined , packageJSON , true ) ;
124
159
125
160
// And now fetch each platform specific
126
161
for ( const p of platformSpecificPackages ) {
127
- await acquireRoslyn ( packageJSON , p . platformInfo , true ) ;
162
+ await acquireNugetPackage ( nugetPackageInfo . roslyn , p , packageJSON , true ) ;
128
163
}
129
164
130
165
// Also pull in the Roslyn DevKit dependencies nuget package.
131
- await acquireRoslynDevKit ( packageJSON , true ) ;
166
+ await acquireNugetPackage ( nugetPackageInfo . RoslynDevKit , undefined , packageJSON , true ) ;
132
167
} , 'installDependencies' )
133
168
) ;
134
169
135
- // Install Tasks
136
- async function installRoslyn ( packageJSON : any , platformInfo ?: PlatformInformation ) {
137
- // Install the Roslyn language server bits.
138
- const { packagePath, serverPlatform } = await acquireRoslyn ( packageJSON , platformInfo , false ) ;
139
- await installNuGetPackage (
140
- packagePath ,
141
- path . join ( 'content' , 'LanguageServer' , serverPlatform ) ,
142
- languageServerDirectory
143
- ) ;
170
+ async function acquireAndInstallAllNugetPackages (
171
+ platformInfo : VSIXPlatformInfo | undefined ,
172
+ packageJSON : any ,
173
+ interactive : boolean
174
+ ) {
175
+ for ( const key in nugetPackageInfo ) {
176
+ const nugetPackage = nugetPackageInfo [ key ] ;
177
+ const packagePath = await acquireNugetPackage ( nugetPackage , platformInfo , packageJSON , interactive ) ;
178
+ await installNuGetPackage ( packagePath , nugetPackage , platformInfo ) ;
179
+ }
180
+ }
144
181
145
- // Install Roslyn DevKit dependencies.
146
- const roslynDevKitPackagePath = await acquireRoslynDevKit ( packageJSON , false ) ;
147
- await installNuGetPackage ( roslynDevKitPackagePath , 'content' , devKitDependenciesDirectory ) ;
182
+ async function acquireNugetPackage (
183
+ nugetPackageInfo : NugetPackageInfo ,
184
+ platformInfo : VSIXPlatformInfo | undefined ,
185
+ packageJSON : any ,
186
+ interactive : boolean
187
+ ) {
188
+ const packageVersion = packageJSON . defaults [ nugetPackageInfo . packageJsonName ] ;
189
+ const packageName = nugetPackageInfo . getPackageName ( platformInfo ) ;
190
+ const packagePath = await restoreNugetPackage ( packageName , packageVersion , interactive ) ;
191
+ return packagePath ;
148
192
}
149
193
150
- async function installNuGetPackage ( pathToPackage : string , contentPath : string , outputPath : string ) {
194
+ async function installNuGetPackage (
195
+ pathToPackage : string ,
196
+ nugetPackageInfo : NugetPackageInfo ,
197
+ platformInfo : VSIXPlatformInfo | undefined
198
+ ) {
151
199
// Get the directory containing the content.
152
- const contentDirectory = path . join ( pathToPackage , contentPath ) ;
200
+ const pathToContentInNugetPackage = nugetPackageInfo . getPackageContentPath ( platformInfo ) ;
201
+ const contentDirectory = path . join ( pathToPackage , pathToContentInNugetPackage ) ;
153
202
if ( ! fs . existsSync ( contentDirectory ) ) {
154
- throw new Error ( `Failed to find NuGet package content at ${ contentDirectory } ` ) ;
203
+ throw new Error (
204
+ `Failed to find NuGet package content at ${ contentDirectory } for ${ nugetPackageInfo . getPackageName (
205
+ platformInfo
206
+ ) } `
207
+ ) ;
155
208
}
156
209
157
210
const numFilesToCopy = fs . readdirSync ( contentDirectory ) . length ;
158
211
159
212
console . log ( `Extracting content from ${ contentDirectory } ` ) ;
160
213
161
- // Copy the files to the language server directory.
214
+ // Copy the files to the specified output directory.
215
+ const outputPath = nugetPackageInfo . vsixOutputPath ;
162
216
fs . mkdirSync ( outputPath ) ;
163
217
fsextra . copySync ( contentDirectory , outputPath ) ;
164
218
const numCopiedFiles = fs . readdirSync ( outputPath ) . length ;
@@ -169,43 +223,6 @@ async function installNuGetPackage(pathToPackage: string, contentPath: string, o
169
223
}
170
224
}
171
225
172
- async function acquireRoslyn (
173
- packageJSON : any ,
174
- platformInfo : PlatformInformation | undefined ,
175
- interactive : boolean
176
- ) : Promise < { packagePath : string ; serverPlatform : string } > {
177
- const roslynVersion = packageJSON . defaults . roslyn ;
178
-
179
- // Find the matching server RID for the current platform.
180
- let serverPlatform : string ;
181
- if ( platformInfo === undefined ) {
182
- serverPlatform = 'neutral' ;
183
- } else {
184
- serverPlatform = platformSpecificPackages . find (
185
- ( p ) =>
186
- p . platformInfo . platform === platformInfo . platform &&
187
- p . platformInfo . architecture === platformInfo . architecture
188
- ) ! . rid ;
189
- }
190
-
191
- const packagePath = await acquireNugetPackage (
192
- `Microsoft.CodeAnalysis.LanguageServer.${ serverPlatform } ` ,
193
- roslynVersion ,
194
- interactive
195
- ) ;
196
- return { packagePath, serverPlatform } ;
197
- }
198
-
199
- async function acquireRoslynDevKit ( packageJSON : any , interactive : boolean ) : Promise < string > {
200
- const roslynVersion = packageJSON . defaults . roslyn ;
201
- const packagePath = await acquireNugetPackage (
202
- `Microsoft.VisualStudio.LanguageServices.DevKit` ,
203
- roslynVersion ,
204
- interactive
205
- ) ;
206
- return packagePath ;
207
- }
208
-
209
226
async function installRazor ( packageJSON : any , platformInfo : PlatformInformation ) {
210
227
if ( platformInfo === undefined ) {
211
228
const platformNeutral = new PlatformInformation ( 'neutral' , 'neutral' ) ;
@@ -243,7 +260,7 @@ async function installPackageJsonDependency(
243
260
}
244
261
}
245
262
246
- async function acquireNugetPackage ( packageName : string , packageVersion : string , interactive : boolean ) : Promise < string > {
263
+ async function restoreNugetPackage ( packageName : string , packageVersion : string , interactive : boolean ) : Promise < string > {
247
264
packageName = packageName . toLocaleLowerCase ( ) ;
248
265
const packageOutputPath = path . join ( nugetTempPath , packageName , packageVersion ) ;
249
266
if ( fs . existsSync ( packageOutputPath ) ) {
@@ -310,13 +327,7 @@ async function doPackageOffline(vsixPlatform: VSIXPlatformInfo | undefined) {
310
327
if ( vsixPlatform === undefined ) {
311
328
await buildVsix ( packageJSON , packedVsixOutputRoot , prerelease ) ;
312
329
} else {
313
- await buildVsix (
314
- packageJSON ,
315
- packedVsixOutputRoot ,
316
- prerelease ,
317
- vsixPlatform . vsceTarget ,
318
- vsixPlatform . platformInfo
319
- ) ;
330
+ await buildVsix ( packageJSON , packedVsixOutputRoot , prerelease , vsixPlatform ) ;
320
331
}
321
332
} catch ( err ) {
322
333
const message = ( err instanceof Error ? err . stack : err ) ?? '<unknown error>' ;
@@ -340,22 +351,16 @@ async function cleanAsync() {
340
351
] ) ;
341
352
}
342
353
343
- async function buildVsix (
344
- packageJSON : any ,
345
- outputFolder : string ,
346
- prerelease : boolean ,
347
- vsceTarget ?: string ,
348
- platformInfo ?: PlatformInformation
349
- ) {
350
- await installRoslyn ( packageJSON , platformInfo ) ;
354
+ async function buildVsix ( packageJSON : any , outputFolder : string , prerelease : boolean , platformInfo ?: VSIXPlatformInfo ) {
355
+ await acquireAndInstallAllNugetPackages ( platformInfo , packageJSON , false ) ;
351
356
352
357
if ( platformInfo != null ) {
353
- await installRazor ( packageJSON , platformInfo ) ;
354
- await installDebugger ( packageJSON , platformInfo ) ;
358
+ await installRazor ( packageJSON , platformInfo . platformInfo ) ;
359
+ await installDebugger ( packageJSON , platformInfo . platformInfo ) ;
355
360
}
356
361
357
- const packageFileName = getPackageName ( packageJSON , vsceTarget ) ;
358
- await createPackageAsync ( outputFolder , prerelease , packageFileName , vsceTarget ) ;
362
+ const packageFileName = getPackageName ( packageJSON , platformInfo ?. vsceTarget ) ;
363
+ await createPackageAsync ( outputFolder , prerelease , packageFileName , platformInfo ?. vsceTarget ) ;
359
364
}
360
365
361
366
function getPackageName ( packageJSON : any , vscodePlatformId ?: string ) {
0 commit comments