Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose version of local tool. #58

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<VersionPrefix>5.19.1</VersionPrefix>
<VersionPrefix>5.20.0</VersionPrefix>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
17 changes: 12 additions & 5 deletions src/Faithlife.Build/DotNetLocalTool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json;
using NuGet.Versioning;
using static Faithlife.Build.DotNetRunner;

namespace Faithlife.Build;
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand All @@ -61,6 +62,11 @@ public static DotNetLocalTool CreateFrom(string directory, string name) =>
/// <param name="directory">The directory from which the tool would be run.</param>
public static bool AnyFrom(string directory) => GetDotNetLocalTools(directory).Any();

/// <summary>
/// The version of the tool.
/// </summary>
public NuGetVersion Version { get; }

/// <summary>
/// Runs the local tool with the specified arguments.
/// </summary>
Expand Down Expand Up @@ -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();
}

Expand Down
3 changes: 2 additions & 1 deletion src/Faithlife.Build/DotNetTools.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Globalization;
using System.Text.RegularExpressions;
using NuGet.Versioning;
using static Faithlife.Build.AppRunner;
using static Faithlife.Build.DotNetRunner;

Expand Down Expand Up @@ -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));
}

/// <summary>
Expand Down