From a15762da63c05e9a05012517fc795c133c8c022f Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Mon, 15 Aug 2022 14:46:23 +0200 Subject: [PATCH] (#2484) Documentation on multiple actions per task (#2487) in Cake scripting. Also added an example for the Run() override in Frosting. --- .../writing-builds/tasks/defining-tasks.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/input/docs/writing-builds/tasks/defining-tasks.md b/input/docs/writing-builds/tasks/defining-tasks.md index b60975ca167..95de1c3f7c2 100644 --- a/input/docs/writing-builds/tasks/defining-tasks.md +++ b/input/docs/writing-builds/tasks/defining-tasks.md @@ -13,6 +13,23 @@ Task("A") }); ``` +In script for [Cake .NET Tool], each task can have one or more actions to be executed when the task is executed. +Those actions are defined using the `Does` (see above) and `DoesForEach` (see [tasks for collections](./running-task-for-collections)) methods. +Both methods can be chained to define more than one action per task. As an example: + +```csharp +Task("A") +.Does(() => +{ + Information("This action runs first."); +}).DoesForEach(GetFiles("./**/*"), f => +{ + Information("Found file: "+f); +}).Does(() => { + Information("This action runs last."); +}); +``` + # Defining tasks in Cake Frosting To define a task in [Cake Frosting] create a class inheriting from [FrostingTask]: @@ -24,6 +41,19 @@ public class TaskA : FrostingTask } ``` +To define the action of a task in [Cake Frosting], override the `Run` method: + +```csharp +[TaskName("A")] +public class TaskA : FrostingTask +{ + public override void Run(Context context) + { + context.Information("This task runs..."); + } +} +``` + [Cake .NET Tool]: /docs/running-builds/runners/dotnet-tool [Cake Frosting]: /docs/running-builds/runners/cake-frosting [FrostingTask]: /api/Cake.Frosting/FrostingTask/