Reusing Builds

Cake supports different ways to share build code across multiple projects and repositories.

Method Sharing of classes Sharing of aliases Sharing of tasks
Recipe NuGet packages
Addins
Assemblies in NuGet packages

Recipe NuGet packages

Cake build scripts can be published as NuGet packages, so called Recipes. These packages can contain shared tasks and can be consumed by other build scripts.

Writing Recipe NuGet packages

To create a Recipe NuGet package add the .cake files to the Content folder in the NuGet package.

Consuming Recipe NuGet packages

The load directive can be used with the nuget scheme to download the Recipe NuGet packages and load all .cake files in the content folder. The following example loads version 1.0.0 of the MyRecipePackage NuGet package:

#load nuget:?package=MyRecipePackage&version=1.0.0

The package can be added to the packages.config file. The following example loads version 1.0.0 of the MyRecipePackage NuGet package:

<package id="MyRecipePackage" version="1.0.0" />

Additionally the required files need to be loaded using the load directive. The following example loads the MyScript file which is part of the MyRecipePackage package:

#load tools/MyRecipePackage/content/MyScript.cake

Addins

Code can be shared as a Cake addin which provides script aliases that can be used in Cake builds.

Writing addins

See Creating addins for instructions how to create your custom addin.

Consuming addins

Addins can be loaded using the addin directive.

Assemblies in NuGet packages

Classes can be shared in .NET assemblies deployed in NuGet packages.

Consuming assemblies from NuGet packages

NuGet packages can be loaded using the addin directive.