Skip to content

Commit

Permalink
Merge pull request #58 from ejball/local-tool-version
Browse files Browse the repository at this point in the history
  • Loading branch information
ejball authored Dec 29, 2023
2 parents 60ba44f + 6eff231 commit 02989ad
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
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

0 comments on commit 02989ad

Please sign in to comment.