From f6198b135575636d4d97faef091fa3df76a0f00a Mon Sep 17 00:00:00 2001 From: femsci Date: Thu, 4 Jan 2024 16:56:44 +0100 Subject: [PATCH] Updater poc --- .../Nyanbyte.DotnetTools.Update.csproj | 9 ++++ src/Nyanbyte.DotnetTools.Update/Program.cs | 43 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/Nyanbyte.DotnetTools.Update/Nyanbyte.DotnetTools.Update.csproj b/src/Nyanbyte.DotnetTools.Update/Nyanbyte.DotnetTools.Update.csproj index 2150e37..b0d28b5 100644 --- a/src/Nyanbyte.DotnetTools.Update/Nyanbyte.DotnetTools.Update.csproj +++ b/src/Nyanbyte.DotnetTools.Update/Nyanbyte.DotnetTools.Update.csproj @@ -5,6 +5,15 @@ net8.0 enable enable + true + update + ./nupkg + + + + + + diff --git a/src/Nyanbyte.DotnetTools.Update/Program.cs b/src/Nyanbyte.DotnetTools.Update/Program.cs index 3751555..bf8719b 100644 --- a/src/Nyanbyte.DotnetTools.Update/Program.cs +++ b/src/Nyanbyte.DotnetTools.Update/Program.cs @@ -1,2 +1,41 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using System.Diagnostics; +using Microsoft.Build.Evaluation; +using Microsoft.Build.Locator; + +internal class Program +{ + private static void Main(string[] args) + { + string path = args.Length > 0 ? args[0] : Environment.CurrentDirectory; + MSBuildLocator.RegisterDefaults(); + Run(path); + } + + private static void Run(string path) + { + Console.WriteLine(path); + var projs = Directory.GetFiles(path, "*.csproj", SearchOption.AllDirectories).ToHashSet(); + + HashSet tasks = []; + + foreach (var projectPath in projs) + { + Project project = Project.FromFile(projectPath, new()); + foreach (var pkg in project.GetItems("PackageReference")) + { + string pkgName = pkg.EvaluatedInclude; + string version = pkg.GetMetadataValue("Version"); + + Console.WriteLine($"Updating {pkgName} from v{version}..."); + Task t = Task.Run(async () => + { + var proc = Process.Start("dotnet", $"add {projectPath} package {pkgName}"); + await proc.WaitForExitAsync(); + }); + tasks.Add(t); + } + } + + Task.WaitAll(tasks.ToArray(), TimeSpan.FromMinutes(5)); + } +}