Skip to content

Commit 11d259c

Browse files
committed
Fixing GetSdk bug.
1 parent d387982 commit 11d259c

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

Nodejs/MigrateToJsps/Jsps/EsprojFileModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace MigrateToJsps
77
public class EsprojFile
88
{
99
[XmlAttribute(AttributeName = "Sdk")]
10-
public string Sdk = @"Microsoft.VisualStudio.JavaScript.Sdk/1.0.1635611";
10+
public string Sdk = @"Microsoft.VisualStudio.JavaScript.Sdk/1.0.2266548";
1111

1212
[XmlElement(ElementName = "PropertyGroup")]
1313
public EsprojPropertyGroup PropertyGroup { get; set; }

Nodejs/MigrateToJsps/Jsps/EsprojFileWriter.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,26 @@ private static JObject ReadPackageJson(string projectDir)
114114

115115
private static string GetSdkVersion()
116116
{
117-
// Use the installed version of JSPS on the NuGet fallback folder.
118-
var versions = Directory.GetDirectories(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft Visual Studio", "Shared", "NuGetPackages", "microsoft.visualstudio.javascript.sdk"));
119-
var newestVersion = versions
120-
.Select(v =>
121-
{
122-
Version.TryParse(Path.GetFileName(v), out var version);
123-
return version;
124-
})
125-
.OrderByDescending(v => v)
126-
.FirstOrDefault();
117+
Version newestVersion = null;
118+
119+
try
120+
{
121+
// Use the installed version of JSPS on the NuGet fallback folder.
122+
var versions = Directory.GetDirectories(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft Visual Studio", "Shared", "NuGetPackages", "microsoft.visualstudio.javascript.sdk"));
123+
newestVersion = versions
124+
.Select(v =>
125+
{
126+
Version.TryParse(Path.GetFileName(v), out var version);
127+
return version;
128+
})
129+
.OrderByDescending(v => v)
130+
.FirstOrDefault();
131+
}
132+
catch (Exception)
133+
{
134+
// If the SDK version is not found on NuGet fallback folder, use the one hardcoded on EsProjFileModel
135+
return null;
136+
}
127137

128138
return newestVersion?.ToString();
129139
}

0 commit comments

Comments
 (0)