Running Targets

To run a target, use the RunTarget method. 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.exe will also be accesible 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.exe. Thus, we can run the "Publish" target by calling:

./build.ps1 -Target Publish