Updater poc
This commit is contained in:
parent
6bbcec53a3
commit
f6198b1355
2 changed files with 50 additions and 2 deletions
|
@ -5,6 +5,15 @@
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
<PackAsTool>true</PackAsTool>
|
||||||
|
<ToolCommandName>update</ToolCommandName>
|
||||||
|
<PackageOutputPath>./nupkg</PackageOutputPath>
|
||||||
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Build" Version="17.8.3" ExcludeAssets="runtime" />
|
||||||
|
<PackageReference Include="Microsoft.Build.Locator" Version="1.6.10" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,2 +1,41 @@
|
||||||
// See https://aka.ms/new-console-template for more information
|
using System.Diagnostics;
|
||||||
Console.WriteLine("Hello, World!");
|
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<Task> 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue