context.DotNetTool fails after update to 5.1.0 from 5.0.0
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
Same issue with version 6.0.0 using .NET 10.
@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:
Running with Cake.Tool v6.0.0
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?
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 thank you for providing that. I can confirm that this works as expected.
@perclausen does this also work for you?
@gep13 @devlead thanks, can confirm DotNetTool(string.Empty, "tool", "restore"); is working 👍
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")
});
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")
});