Setting Up A New Project

This is a guide to get started with Cake and to show you how Cake works.

Choose your runner

Choose the runner suitable for your scenario. See Running Cake Scripts for other possibilities how to run Cake scripts.

For this tutorial we use the recommended approach using the .NET Core Tool on .NET Core 3.0 and newer.

Make sure to have a tool manifest available in your repository or create one using the following command:

dotnet new tool-manifest

Install Cake as a local tool using the dotnet tool command:

dotnet tool install Cake.Tool --version x.y.z

See Bootstrapping .NET Core Tool for details about the bootstrapping process.

Create initial build script

Create a file called build.cake with the following content:

var target = Argument("target", "Test");
var configuration = Argument("configuration", "Release");

//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////

Task("Clean")
    .WithCriteria(c => HasArgument("rebuild"))
    .Does(() =>
{
    CleanDirectory($"./src/Example/bin/{configuration}");
});

Task("Build")
    .IsDependentOn("Clean")
    .Does(() =>
{
    DotNetCoreBuild("./src/Example.sln", new DotNetCoreBuildSettings
    {
        Configuration = configuration,
    });
});

Task("Test")
    .IsDependentOn("Build")
    .Does(() =>
{
    DotNetCoreTest("./src/Example.sln", new DotNetCoreTestSettings
    {
        Configuration = configuration,
        NoBuild = true,
    });
});

//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////

RunTarget(target);

Run build script

Run the build script using the .NET CLI:

dotnet cake