From 93ad6327fe20f0a5eec0b5fc20ae83ead4bdfb9d Mon Sep 17 00:00:00 2001 From: Ed Ball Date: Fri, 29 Dec 2023 12:23:12 -0800 Subject: [PATCH 1/2] Expose version of local tool. --- src/Faithlife.Build/DotNetLocalTool.cs | 17 ++++++++++++----- src/Faithlife.Build/DotNetTools.cs | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Faithlife.Build/DotNetLocalTool.cs b/src/Faithlife.Build/DotNetLocalTool.cs index d249d06..70bcbad 100644 --- a/src/Faithlife.Build/DotNetLocalTool.cs +++ b/src/Faithlife.Build/DotNetLocalTool.cs @@ -1,4 +1,5 @@ using System.Text.Json; +using NuGet.Versioning; using static Faithlife.Build.DotNetRunner; namespace Faithlife.Build; @@ -47,7 +48,7 @@ public static DotNetLocalTool CreateFrom(string directory, string name) => return null; if (foundTools.Count > 1) throw new BuildException($"Multiple tools were found matching '{name}'."); - return new DotNetLocalTool(directory, foundTools[0].Command); + return new DotNetLocalTool(directory, foundTools[0].Command, foundTools[0].Version); } /// @@ -61,6 +62,11 @@ public static DotNetLocalTool CreateFrom(string directory, string name) => /// The directory from which the tool would be run. public static bool AnyFrom(string directory) => GetDotNetLocalTools(directory).Any(); + /// + /// The version of the tool. + /// + public NuGetVersion Version { get; } + /// /// Runs the local tool with the specified arguments. /// @@ -99,23 +105,24 @@ public int Run(AppRunnerSettings settings) return RunDotNet(settings); } - internal DotNetLocalTool(string directory, string name) + internal DotNetLocalTool(string directory, string name, NuGetVersion version) { m_directory = directory; m_name = name; + Version = version; } - private static IReadOnlyList<(string Package, string Command)> GetDotNetLocalTools(string directory) + private static IReadOnlyList<(string Package, NuGetVersion Version, string Command)> GetDotNetLocalTools(string directory) { var manifestPath = TryGetDotNetLocalToolManifestPath(Path.GetFullPath(directory)); if (manifestPath is null) - return Array.Empty<(string, string)>(); + return Array.Empty<(string, NuGetVersion, string)>(); return JsonDocument.Parse(File.ReadAllText(manifestPath)) .RootElement .GetProperty("tools") .EnumerateObject() - .SelectMany(tool => tool.Value.GetProperty("commands").EnumerateArray().Select(x => (tool.Name, x.GetString()!))) + .SelectMany(tool => tool.Value.GetProperty("commands").EnumerateArray().Select(x => (tool.Name, NuGetVersion.Parse(tool.Value.GetProperty("version").GetString()!), x.GetString()!))) .ToList(); } diff --git a/src/Faithlife.Build/DotNetTools.cs b/src/Faithlife.Build/DotNetTools.cs index 09e3fca..58e5cfb 100644 --- a/src/Faithlife.Build/DotNetTools.cs +++ b/src/Faithlife.Build/DotNetTools.cs @@ -1,5 +1,6 @@ using System.Globalization; using System.Text.RegularExpressions; +using NuGet.Versioning; using static Faithlife.Build.AppRunner; using static Faithlife.Build.DotNetRunner; @@ -69,7 +70,7 @@ public DotNetLocalTool GetLocalTool(string package, string? name = null) RunDotNet(new AppRunnerSettings { Arguments = args, WorkingDirectory = directory }); } - return new DotNetLocalTool(directory, name ?? package); + return new DotNetLocalTool(directory, name ?? package, new NuGetVersion(0, 0, 0)); } /// From 6eff23161b1c8af45edb55454b00ff5def1b501a Mon Sep 17 00:00:00 2001 From: Ed Ball Date: Fri, 29 Dec 2023 12:23:50 -0800 Subject: [PATCH 2/2] Publish 5.20.0. --- Directory.Build.props | 2 +- ReleaseNotes.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index f819bf8..38c25b8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 5.19.1 + 5.20.0 11.0 enable enable diff --git a/ReleaseNotes.md b/ReleaseNotes.md index cfd6cff..fff0f86 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,5 +1,9 @@ # Release Notes +## 5.20.0 + +* Add `Version` to `DotNetLocalTool`. + ## 5.19.1 * Never publish NuGet package with version `0.0.0`.