cake icon indicating copy to clipboard operation
cake copied to clipboard

context.DotNetTool fails after update to 5.1.0 from 5.0.0

Open perclausen opened this issue 2 months ago • 5 comments

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have searched issues to ensure it has not already been reported

Cake runner

Cake Frosting

Cake version

5.1.0

Operating system

Windows 11

Operating system architecture

x64

CI Server

No response

What are you seeing?

Running below snippet work in v5.0.0: context.DotNetTool("tool restore");

but fails in v5.1.0 with below error:

========================================
Restore
========================================
Restoring dotnet tools...
Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET program, but dotnet-tool restore does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
An error occurred when executing task 'Restore'.
Cake Restore error: .NET CLI: Process returned an error (exit code 1).

Entire restore task:

[IsDependentOn(typeof(SharedAssemblyInfo))]
[TaskDescription("Restore solution references using ./nuget.config")]
public class Restore : FrostingTask<Context>
{
    public override void Run(Context context)
    {
        context.LogCommand("Restoring dotnet tools...");
        context.DotNetTool("tool restore");

        context.LogCommand($"Restoring {context.Solution}...");
        context.DotNetRestore(context.Solution, new DotNetRestoreSettings
        {
            Force = true,
            Interactive = false,
            MSBuildSettings = context.MSBuildSettings
        });
    }
}

I'm using .NET SDK 8.0.415.

What is expected?

That context.DotNetTool("tool restore"); works like it did in v5.0.0.

Steps to Reproduce

Create a task that invokes context.DotNetTool("tool restore");

dotnet-tools.json in ./.config

Output log

No response

perclausen avatar Oct 31 '25 22:10 perclausen

Same issue with version 6.0.0 using .NET 10.

perclausen avatar Nov 21 '25 17:11 perclausen

@perclausen thank you for reporting this issue!

I am able to replicate the problem that you have brought up!

Running with Cake.Tool v5.0.0: Image

Running with Cake.Tool v6.0.0

Image

It seems that there might have been a change in the quoting of arguments, that is causing the problem that you are seeing.

Namely:

Executing: "C:/Program Files/dotnet/dotnet.exe" tool restore

to

Executing: "C:/Program Files/dotnet/dotnet.exe" "tool restore"

@devlead are you aware of any changes in this area?

gep13 avatar Nov 24 '25 12:11 gep13

It was introduced in https://github.com/cake-build/cake/pull/4537 , what will work today is below with command and arguments separated with no project specified.

DotNetTool(string.Empty, "tool", "restore");

devlead avatar Nov 24 '25 12:11 devlead

@devlead thank you for providing that. I can confirm that this works as expected.

@perclausen does this also work for you?

gep13 avatar Nov 24 '25 12:11 gep13

@gep13 @devlead thanks, can confirm DotNetTool(string.Empty, "tool", "restore"); is working 👍

perclausen avatar Nov 28 '25 14:11 perclausen

However, hope this issue will be fixed as more complex usage like the below also fails.

        context.LogCommand("Building web-site...");
        context.DotNetTool("docfx build", new DotNetToolSettings
        {
            WorkingDirectory = "./docfx",
            ArgumentCustomization = args => args
                .Append($"--metadata _appFooter=\"Version {context.Version} build {context.BuildNumber}\"")
                .Append("--warningsAsErrors")
        });

perclausen avatar Dec 13 '25 00:12 perclausen

However, hope this issue will be fixed as more complex usage like the below also fails.

    context.LogCommand("Building web-site...");
    context.DotNetTool("docfx build", new DotNetToolSettings
    {
        WorkingDirectory = "./docfx",
        ArgumentCustomization = args => args
            .Append($"--metadata _appFooter=\"Version {context.Version} build {context.BuildNumber}\"")
            .Append("--warningsAsErrors")
    });

In this scenario docfx is the tool and build is a command of that tool, so it should work if you add build as the first argument, something like

        context.LogCommand("Building web-site...");
        context.DotNetTool("docfx", new DotNetToolSettings
        {
            WorkingDirectory = "./docfx",
            ArgumentCustomization = args => args
                .Append("build")
                .Append($"--metadata _appFooter=\"Version {context.Version} build {context.BuildNumber}\"")
                .Append("--warningsAsErrors")
        });

devlead avatar Dec 13 '25 23:12 devlead