Skip to content

Commit ff7d05c

Browse files
committed
Fix ambiguity between package ID and command name in NETCoreToolHelper
1 parent 03be3b4 commit ff7d05c

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/features/Riverside.CompilerPlatform.Features.Kiota/KiotaGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected override void OnBeforeGeneration(GeneratorContext context, Cancellatio
7878
try
7979
{
8080
var (installed, installError) = NETCoreToolHelpers
81-
.EnsureToolAsync("Microsoft.OpenApi.Kiota", ToolDirectory, version)
81+
.EnsureToolAsync("Microsoft.OpenApi.Kiota", ToolDirectory, version, commandName: "kiota")
8282
.GetAwaiter().GetResult();
8383

8484
if (!installed)

src/roslyn/Riverside.CompilerPlatform.Extensions/Helpers/NETCoreToolHelpers.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,28 @@ public static string GetExecutablePath(string toolDirectory, string toolName)
3131
/// <item>Installation succeeds when the executable is present after the above steps.</item>
3232
/// </list>
3333
/// </remarks>
34-
/// <param name="toolName">The NuGet package ID of the tool (e.g. <c>Riverside.JsonBinder.Console</c>).</param>
34+
/// <param name="packageId">The NuGet package ID of the tool (e.g. <c>Riverside.JsonBinder.Console</c>).</param>
3535
/// <param name="toolDirectory">The directory to install the tool into, passed to <c>--tool-path</c>.</param>
3636
/// <param name="version">
3737
/// A specific version to pin. Pass <see langword="null"/> to install or keep the latest.
3838
/// </param>
3939
/// <param name="timeout">Maximum wait time per install or update process. Defaults to 5 minutes.</param>
40+
/// <param name="commandName">
41+
/// The executable/command name to look for in <paramref name="toolDirectory"/> (e.g. <c>jsonbinder</c>).
42+
/// If <see langword="null"/>, <paramref name="packageId"/> is used as the command name.
43+
/// </param>
4044
/// <returns>
4145
/// A tuple where <c>Success</c> is <see langword="true"/> when the executable is available, and <c>Error</c> carries the captured stderr when installation fails.
4246
/// </returns>
4347
public static async Task<(bool Success, string? Error)> EnsureToolAsync(
44-
string toolName,
48+
string packageId,
4549
string toolDirectory,
4650
string? version = null,
47-
TimeSpan? timeout = null)
51+
TimeSpan? timeout = null,
52+
string? commandName = null)
4853
{
49-
var exe = GetExecutablePath(toolDirectory, toolName);
54+
var exeName = string.IsNullOrWhiteSpace(commandName) ? packageId : commandName;
55+
var exe = GetExecutablePath(toolDirectory, exeName!);
5056
var effectiveTimeout = timeout ?? TimeSpan.FromMinutes(5);
5157

5258
Directory.CreateDirectory(toolDirectory);
@@ -58,14 +64,14 @@ public static string GetExecutablePath(string toolDirectory, string toolName)
5864
var versionArg = string.IsNullOrWhiteSpace(version) ? string.Empty : $" --version {version}";
5965

6066
var installResult = await ProcessHelpers.RunNETCoreCliAsync(
61-
$"tool install {toolName} {toolPathArg}{versionArg}", effectiveTimeout);
67+
$"tool install {packageId} {toolPathArg}{versionArg}", effectiveTimeout);
6268

6369
if (installResult.ExitCode == 0)
6470
return (true, null);
6571

6672
// install exits non-zero when the tool is already present; attempt an update instead
6773
var updateResult = await ProcessHelpers.RunNETCoreCliAsync(
68-
$"tool update {toolName} {toolPathArg}{versionArg}", effectiveTimeout);
74+
$"tool update {packageId} {toolPathArg}{versionArg}", effectiveTimeout);
6975

7076
return File.Exists(exe)
7177
? (true, null)

0 commit comments

Comments
 (0)