|
12 | 12 | using System.Xml; |
13 | 13 | using Microsoft.NodejsTools.Telemetry; |
14 | 14 | using Microsoft.VisualStudio.Language.Intellisense; |
| 15 | +using Microsoft.VisualStudio.Shell.Interop; |
15 | 16 | using Microsoft.VisualStudioTools; |
16 | 17 |
|
17 | 18 | namespace Microsoft.NodejsTools.Project.ImportWizard |
@@ -256,9 +257,10 @@ public Task<string> CreateRequestedProjectAsync() |
256 | 257 | Guid projectGuid; |
257 | 258 | try |
258 | 259 | { |
| 260 | + string typeScriptVersion = GetLatestAvailableTypeScriptVersionFromSetup(); |
259 | 261 | using (var writer = GetDefaultWriter(projectPath)) |
260 | 262 | { |
261 | | - WriteProjectXml(writer, projectPath, sourcePath, filters, startupFile, true, out projectGuid); |
| 263 | + WriteProjectXml(writer, projectPath, sourcePath, filters, startupFile, typeScriptVersion, true, out projectGuid); |
262 | 264 | } |
263 | 265 | NodejsPackage.Instance?.TelemetryLogger.LogProjectImported(projectGuid); |
264 | 266 | success = true; |
@@ -304,6 +306,7 @@ internal static void WriteProjectXml( |
304 | 306 | string sourcePath, |
305 | 307 | string filters, |
306 | 308 | string startupFile, |
| 309 | + string typeScriptVersion, |
307 | 310 | bool excludeNodeModules, |
308 | 311 | out Guid projectGuid |
309 | 312 | ) |
@@ -346,6 +349,10 @@ out Guid projectGuid |
346 | 349 | writer.WriteElementString("TypeScriptSourceMap", "true"); |
347 | 350 | writer.WriteElementString("TypeScriptModuleKind", "CommonJS"); |
348 | 351 | writer.WriteElementString("EnableTypeScript", "true"); |
| 352 | + if (typeScriptVersion != null) |
| 353 | + { |
| 354 | + writer.WriteElementString("TypeScriptToolsVersion", typeScriptVersion); |
| 355 | + } |
349 | 356 | } |
350 | 357 |
|
351 | 358 | writer.WriteStartElement("VisualStudioVersion"); |
@@ -520,6 +527,35 @@ private static IEnumerable<string> EnumerateAllFiles(string source, string filte |
520 | 527 |
|
521 | 528 | return res; |
522 | 529 | } |
| 530 | + |
| 531 | + private const string tsSdkSetupPackageIdPrefix = "Microsoft.VisualStudio.Component.TypeScript."; |
| 532 | + |
| 533 | + private static string GetLatestAvailableTypeScriptVersionFromSetup() |
| 534 | + { |
| 535 | + var setupCompositionService = (IVsSetupCompositionService)CommonPackage.GetGlobalService(typeof(SVsSetupCompositionService)); |
| 536 | + |
| 537 | + // Populate the package status |
| 538 | + uint count = 0; |
| 539 | + uint sizeNeeded = 0; |
| 540 | + IVsSetupPackageInfo[] packages = null; |
| 541 | + setupCompositionService.GetSetupPackagesInfo(count, packages, out sizeNeeded); |
| 542 | + |
| 543 | + if (sizeNeeded > 0) |
| 544 | + { |
| 545 | + packages = new IVsSetupPackageInfo[sizeNeeded]; |
| 546 | + count = sizeNeeded; |
| 547 | + setupCompositionService.GetSetupPackagesInfo(count, packages, out sizeNeeded); |
| 548 | + |
| 549 | + return packages.Where(p => (__VsSetupPackageState)p.CurrentState == __VsSetupPackageState.INSTALL_PACKAGE_PRESENT) |
| 550 | + .Select(p => p.PackageId) |
| 551 | + .Where(p => p.StartsWith(tsSdkSetupPackageIdPrefix)) |
| 552 | + .Select(p => p.Substring(tsSdkSetupPackageIdPrefix.Length, p.Length - tsSdkSetupPackageIdPrefix.Length)) |
| 553 | + .OrderByDescending(v => v) |
| 554 | + .First(); |
| 555 | + } |
| 556 | + |
| 557 | + return ""; |
| 558 | + } |
523 | 559 | } |
524 | 560 | } |
525 | 561 |
|
0 commit comments