1000x .net upgrade perf
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
using DotNetSolutionTools.Core.Common;
|
using DotNetSolutionTools.Core.Common;
|
||||||
using DotNetSolutionTools.Core.Infrastructure;
|
using DotNetSolutionTools.Core.Infrastructure;
|
||||||
using Microsoft.Build.Construction;
|
using Microsoft.Build.Construction;
|
||||||
using Microsoft.Build.Definition;
|
|
||||||
using Microsoft.Build.Evaluation;
|
|
||||||
using NuGet.Versioning;
|
using NuGet.Versioning;
|
||||||
|
|
||||||
namespace DotNetSolutionTools.Core;
|
namespace DotNetSolutionTools.Core;
|
||||||
@@ -47,20 +45,15 @@ public static class DotNetUpgrade
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task UpdatePackagesToLatest(ProjectRootElement project)
|
private static async Task UpdatePackagesToLatest(ProjectRootElement project)
|
||||||
{
|
{
|
||||||
Project? evalProject = null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
evalProject = Project.FromProjectRootElement(
|
var packages = project
|
||||||
project,
|
|
||||||
new ProjectOptions() { LoadSettings = ProjectLoadSettings.IgnoreMissingImports }
|
|
||||||
);
|
|
||||||
var packages = evalProject
|
|
||||||
.Items.Where(x =>
|
.Items.Where(x =>
|
||||||
x.ItemType == "PackageReference"
|
x.ItemType == "PackageReference"
|
||||||
&& x.HasMetadata("Version")
|
&& x.Metadata.Any(s => s.Name == "Version")
|
||||||
&& x.EvaluatedInclude.StartsWith("Microsoft.")
|
&& x.Include.StartsWith("Microsoft.")
|
||||||
)
|
)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
@@ -68,8 +61,8 @@ public static class DotNetUpgrade
|
|||||||
.Select(x => new
|
.Select(x => new
|
||||||
{
|
{
|
||||||
Package = x,
|
Package = x,
|
||||||
Name = x.EvaluatedInclude,
|
Name = x.Include,
|
||||||
NugetVersion = NuGetVersion.Parse(x.Metadata.First(s => s.Name == "Version").UnevaluatedValue)
|
NugetVersion = NuGetVersion.Parse(x.Metadata.First(s => s.Name == "Version").Value)
|
||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
@@ -84,7 +77,7 @@ public static class DotNetUpgrade
|
|||||||
if (latestNugetVersion > package.NugetVersion)
|
if (latestNugetVersion > package.NugetVersion)
|
||||||
{
|
{
|
||||||
shouldSave = true;
|
shouldSave = true;
|
||||||
package.Package.SetMetadataValue("Version", latestNugetVersion.ToString());
|
package.Package.Metadata.First(s => s.Name == "Version").Value = latestNugetVersion.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,13 +92,5 @@ public static class DotNetUpgrade
|
|||||||
Console.WriteLine(e);
|
Console.WriteLine(e);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (evalProject is not null)
|
|
||||||
{
|
|
||||||
ProjectCollection.GlobalProjectCollection.UnloadProject(evalProject);
|
|
||||||
ProjectCollection.GlobalProjectCollection.TryUnloadProject(project);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user