Upgrade single project and nuget lookup fix
This commit is contained in:
@@ -11,30 +11,39 @@ public static class DotNetUpgrade
|
||||
public static async Task UpdateProjectsInSolutionToNet80(string solutionFilePath)
|
||||
{
|
||||
var solutionFile = SolutionFile.Parse(solutionFilePath);
|
||||
var csprojList = SolutionProjectParity.GetCSharpProjectObjectsFromSolutionFile(
|
||||
solutionFile
|
||||
);
|
||||
var csprojList = SolutionProjectParity.GetCSharpProjectObjectsFromSolutionFile(solutionFile);
|
||||
await UpdateProjectsToNet80(csprojList);
|
||||
}
|
||||
|
||||
public static async Task UpdateProjectAtPathToNet80(string csprojFilePath)
|
||||
{
|
||||
var csproj = ProjectRootElement.Open(csprojFilePath);
|
||||
await UpdateProjectToNet80(csproj!);
|
||||
}
|
||||
|
||||
private static async Task UpdateProjectsToNet80(List<ProjectRootElement> projects)
|
||||
{
|
||||
foreach (var project in projects)
|
||||
{
|
||||
var targetFramework = project
|
||||
.PropertyGroups
|
||||
.SelectMany(x => x.Properties)
|
||||
.FirstOrDefault(x => x.Name == "TargetFramework");
|
||||
if (targetFramework?.Value is "net8.0" or "net7.0" or "net6.0" or "net5.0")
|
||||
await UpdateProjectToNet80(project);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task UpdateProjectToNet80(ProjectRootElement project)
|
||||
{
|
||||
var targetFramework = project
|
||||
.PropertyGroups
|
||||
.SelectMany(x => x.Properties)
|
||||
.FirstOrDefault(x => x.Name == "TargetFramework");
|
||||
if (targetFramework?.Value is "net8.0" or "net7.0" or "net6.0" or "net5.0")
|
||||
{
|
||||
if (targetFramework.Value is not "net8.0")
|
||||
{
|
||||
if (targetFramework.Value is not "net8.0")
|
||||
{
|
||||
targetFramework.Value = "net8.0";
|
||||
project.Save();
|
||||
FormatCsproj.FormatCsprojFile(project.FullPath);
|
||||
}
|
||||
await UpdatePackagesToLatest(project);
|
||||
targetFramework.Value = "net8.0";
|
||||
project.Save();
|
||||
FormatCsproj.FormatCsprojFile(project.FullPath);
|
||||
}
|
||||
await UpdatePackagesToLatest(project);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,10 +56,16 @@ public static class DotNetUpgrade
|
||||
project,
|
||||
new ProjectOptions() { LoadSettings = ProjectLoadSettings.IgnoreMissingImports }
|
||||
);
|
||||
var packages = evalProject.Items.Where(x =>
|
||||
x.ItemType == "PackageReference" && x.HasMetadata("Version") &&
|
||||
x.EvaluatedInclude.StartsWith("Microsoft.")).ToList();
|
||||
|
||||
var packages = evalProject
|
||||
.Items
|
||||
.Where(
|
||||
x =>
|
||||
x.ItemType == "PackageReference"
|
||||
&& x.HasMetadata("Version")
|
||||
&& x.EvaluatedInclude.StartsWith("Microsoft.")
|
||||
)
|
||||
.ToList();
|
||||
|
||||
var packageNameAndVersion = packages
|
||||
.Select(
|
||||
x =>
|
||||
@@ -68,8 +83,11 @@ public static class DotNetUpgrade
|
||||
var shouldSave = false;
|
||||
foreach (var package in packageNameAndVersion)
|
||||
{
|
||||
var latestNugetVersion = await NugetLookup.FetchPackageMetadataAsync(package.Name);
|
||||
|
||||
var latestNugetVersion = await NugetLookup.FetchPackageMetadataAsync(
|
||||
package.Name,
|
||||
package.NugetVersion.IsPrerelease
|
||||
);
|
||||
|
||||
if (latestNugetVersion > package.NugetVersion)
|
||||
{
|
||||
shouldSave = true;
|
||||
@@ -83,6 +101,11 @@ public static class DotNetUpgrade
|
||||
FormatCsproj.FormatCsprojFile(project.FullPath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (evalProject is not null)
|
||||
|
||||
Reference in New Issue
Block a user