Running Targets

Cake .NET Tool

When using Cake .NET Tool you can use the RunTarget method to run a target. The RunTarget method should be placed at the end of the script.

Task("Default")
    .Does(() =>
{
    Information("Hello World!");
});

RunTarget("Default");

Passing a target to the script

All arguments passed to Cake will also be accessible from the Cake script. You can access the arguments by using the argument DSL.

var target = Argument("target", "Build");

Task("Build")
    .Does(() =>
{
});

Task("Publish")
    .IsDependentOn("Build")
    .Does(() =>
{
});

RunTarget(target);

With this Cake script, you can run a specific target by passing the --target argument to Cake. Thus, we can run the "Publish" target by calling Cake with the following argument:

--target=Publish

The --exclusive parameter causes RunTarget to run only the specified target and no dependencies. The following arguments will run the Publish target without running the Build target:

--target=Publish --exclusive

Cake Frosting

Cake Frosting by default will call a task named Default.

In Cake Frosting it is not possible to define a task other than Default, which is run by default in your build script.

Passing a target to the script

To override the task which should be run Cake Frosting comes with a --target switch:

--target=Publish

The --exclusive parameter causes Cake Frosting to run only the specified target and no dependencies. The following arguments will run the Publish target without running the Build target:

--target=Publish --exclusive