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

Commit

Permalink
return netcoreapp3.1 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarolf committed Mar 24, 2020
1 parent 0191847 commit fbf3580
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
66 changes: 37 additions & 29 deletions src/MSBuild.Conversion.SDK/TargetFrameworkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,51 @@ public static string FindHighestInstalledTargetFramework(bool usePreviewSDK)
throw;
}

// Find templates path
var templatesPath = Path.Combine(sdkPath, "templates");

// Find highest SDK path (should include previews?)
var largestVersion = NuGetVersion.Parse("0.0.0.0");
var templatePath = string.Empty;
foreach (var templateDirectory in Directory.EnumerateDirectories(templatesPath))
try
{
if (NuGetVersion.TryParse(Path.GetFileName(templateDirectory), out var templatesVersion) &&
templatesVersion > largestVersion)
// Find templates path
var templatesPath = Path.Combine(sdkPath, "templates");

// Find highest SDK path (should include previews?)
var largestVersion = NuGetVersion.Parse("0.0.0.0");
var templatePath = string.Empty;
foreach (var templateDirectory in Directory.EnumerateDirectories(templatesPath))
{
if (usePreviewSDK)
if (NuGetVersion.TryParse(Path.GetFileName(templateDirectory), out var templatesVersion) &&
templatesVersion > largestVersion)
{
largestVersion = templatesVersion;
templatePath = Path.GetFullPath(templateDirectory);
}
else if (!templatesVersion.IsPrerelease)
{
largestVersion = templatesVersion;
templatePath = Path.GetFullPath(templateDirectory);
if (usePreviewSDK)
{
largestVersion = templatesVersion;
templatePath = Path.GetFullPath(templateDirectory);
}
else if (!templatesVersion.IsPrerelease)
{
largestVersion = templatesVersion;
templatePath = Path.GetFullPath(templateDirectory);
}
}
}
}

// 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
.Where(x => x.Name.Equals("template.json", StringComparison.OrdinalIgnoreCase) &&
x.FullName.Contains("ClassLibrary-CSharp", StringComparison.OrdinalIgnoreCase)).Single();
using var templatesJson = templatesJsonFile.Open();
// 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
.Where(x => x.Name.Equals("template.json", StringComparison.OrdinalIgnoreCase) &&
x.FullName.Contains("ClassLibrary-CSharp", StringComparison.OrdinalIgnoreCase)).Single();
using var templatesJson = templatesJsonFile.Open();

// read the template.json file to see what the tfm is called
var doc = JsonDocument.ParseAsync(templatesJson).GetAwaiter().GetResult();
// read the template.json file to see what the tfm is called
var doc = JsonDocument.ParseAsync(templatesJson).GetAwaiter().GetResult();

return doc.RootElement.GetProperty("baselines").GetProperty("app").GetProperty("defaultOverrides").GetProperty("Framework").GetString();
}
catch (Exception)
{
return "netcoreapp3.1";
}

return doc.RootElement.GetProperty("baselines").GetProperty("app").GetProperty("defaultOverrides").GetProperty("Framework").GetString();
}
}
}
4 changes: 0 additions & 4 deletions src/try-convert/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ public static int Run(string project, string workspace, string msbuildPath, stri
if (tfm is null)
{
tfm = TargetFrameworkHelper.FindHighestInstalledTargetFramework(allowPreviews);
if (tfm is null)
{
tfm = "netcoreapp3.1";
}
}

var currentDirectory = Environment.CurrentDirectory;
Expand Down

0 comments on commit fbf3580

Please sign in to comment.