Installing and using tools

Installing tools from NuGet

Cake provides different ways to install tool executables available as NuGet packages as part of a build.

Installation method Cake .NET Tool Cake Frosting Cake.Sdk
Pre-processor directive
InstallTool

Installing tools via pre-processor directive

The #tool pre-processor directive for Cake .NET Tool can be used to automatically download a tool and install it in the tools folder.

Out of the box NuGet and .NET Tools (since Cake 1.1) are supported as provider. More providers are available through Modules.

The following example downloads the xunit.runner.console package as part of executing your build script:

#tool "nuget:?package=xunit.runner.console&version=2.4.1"

For more information see #tool pre-processor directive.

Installing tools with InstallTool

Cake Frosting and Cake.Sdk provide an InstallTool method to download a tool and install it:

Out of the box NuGet and .NET Tools (since Cake 1.1) are supported as provider. More providers are available through Modules.

Cake Frosting

The following example downloads the xunit.runner.console package as part of executing your build script:

public class Program : IFrostingStartup
{
    public static int Main(string[] args)
    {
        // Create and run the host.
        return
            new CakeHost()
                .InstallTool(new Uri("nuget:?package=xunit.runner.console&version=2.4.1"))
                .Run(args);
    }
}

Cake.Sdk

The following example downloads the GitVersion.Tool package as part of executing your build script:

#:sdk Cake.Sdk

Setup(context =>
{
    InstallTool("dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=6.3.0");
    var version = GitVersion();
    Information("Building Version: {0}", version.FullSemVer);
});

For more information about using tools with Cake.Sdk see Installing and using tools with Cake.Sdk.

For more information about supported URI string parameters see #tool pre-processor directive.

Installing tools from other providers

Out of the box NuGet and .NET Tools (since Cake 1.1) is supported as provider for Pre-processor directive and InstallTool. More providers are available through Modules.

Using tools from disk

To use a tool that's not available via NuGet or if you prefer to store the tool locally, Cakes tool resolution conventions can be used to resolve the path to the tool and call it through a process alias:

Task("Install-XUnit")
    .Does(()=> {
    FilePath nugetPath = Context.Tools.Resolve("nuget.exe");
    StartProcess(nugetPath, new ProcessSettings {
        Arguments = new ProcessArgumentBuilder()
            .Append("install")
            .Append("xunit.runner.console")
        });
});