Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #391 from ejohnson-dotnet/main
Browse files Browse the repository at this point in the history
Update TargetFrameworkHelper.cs to fix #388
  • Loading branch information
cartermp committed Mar 29, 2021
2 parents c6c5f3c + cef3123 commit 27c7281
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/MSBuild.Conversion.SDK/TargetFrameworkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,17 @@ public static string FindHighestInstalledTargetFramework(bool usePreviewSDK)
}
}

var templateFiles = Directory.EnumerateFiles(templatePath, "microsoft.dotnet.common.projecttemplates.*.nupkg", SearchOption.TopDirectoryOnly);
// get the highest version of the files found, based on NuGetVersion
var templateNugetPackagePath = templateFiles.OrderByDescending(p =>
{
var versionStr = Path.GetFileNameWithoutExtension(p).Substring("microsoft.dotnet.common.projecttemplates.".Length);
//first two numbers in the version are part of the name of the package, not its nuget version.
versionStr = string.Join(".", versionStr.Split(".").Skip(2));
var version = NuGetVersion.Parse(versionStr);
return (!usePreviewSDK && version.IsPrerelease) ? new NuGetVersion(0, 0, 0) : version;
}).First();
// upzip the common project templates into memory
var templateNugetPackagePath = Directory.EnumerateFiles(templatePath, "microsoft.dotnet.common.projecttemplates.*.nupkg", SearchOption.TopDirectoryOnly).Single();
using var templateNugetPackageFile = File.OpenRead(templateNugetPackagePath);
using var templateNugetPackage = new ZipArchive(templateNugetPackageFile, ZipArchiveMode.Read);
var templatesJsonFile = templateNugetPackage.Entries
Expand Down

0 comments on commit 27c7281

Please sign in to comment.