BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Cake Build Tool Updated to .NET 8 in v4.0.0

Cake Build Tool Updated to .NET 8 in v4.0.0

Cake, the open-source .NET build automation system with a full C# DSL, was updated to version 4.0.0 on November 18th 2023, aligning with the release of .NET 8. It now fully supports the most recent version of the .NET runtime. Apart from dependency updates for security reasons, only two minor features were added.

Unzip operations to overwrite the existing target files are now supported. This aligns the Cake tool with the recent visibility update of the overwrite flag in .NET standard ZIP operations in the framework. The second feature enables file timestamp manipulations in Cake scripts, such as changing file creation or last access times.

Cake is a build system running on top of .NET’s native Roslyn compiler. It performs a role similar to the Gulp runner in the JavaScript ecosystem, based on tasks and dependencies between tasks. The developers can invoke the Cake build script, passing the target task to be executed.

A simple Cake script contains tasks that call different build and release-related libraries and tools. For example, the following Cake script runs three tasks: Clean, Build and Test, with Test being a default one.

var target = Argument("target", "Test");
var configuration = Argument("configuration", "Release");
Task("Clean")
	.WithCriteria(c => HasArgument("rebuild"))
	.Does(() =>
{
	CleanDirectory($"./src/Example/bin/{configuration}");
});
Task("Build")
	.IsDependentOn("Clean")
	.Does(() =>
{
	DotNetBuild("./src/Example.sln", new DotNetBuildSettings
	{
    	Configuration = configuration,
	});
});
Task("Test")
	.IsDependentOn("Build")
	.Does(() =>
{
	DotNetTest("./src/Example.sln", new DotNetTestSettings
	{
    	Configuration = configuration,
    	NoBuild = true,
	});
});
RunTarget(target);

Executing this script from the command line, by typing dotnet cake, will run the Test task. However, the Test task depends on the Build task, which in turn depends on the Clean task. Finally, the execution order for the tasks would be Clean, Build, and Test. CleanDirectory, DotNetBuild and DotNetTest are the methods invoking native .NET tooling to clean, build and run tests.

The benefit of using Cake instead of standard .NET build tools is summarised by the Reddit user ‘devlead’ as follows:

If you've got more than one step in your build and release process, then it can be an excellent tool to declare the steps in repeatable way in a real full programming language with C#. In a cross-platform and cross-environment way, which essentially means it'll run on Linux, MacOS, and Windows, it'll run locally and any build/release server/service.

Devlead also highlighted the convenience of using the language that the development team already knows, C#:

Being able to test and debug workflow locally can be a real time-saver, your feedback loop is much quicker, in contrast to authoring a yaml file, committing it to git, waiting for CI to start, grab some coffee and then reason why it failed.

If your a .NET team, then you're by using C# able to use skill you already have, and things like if statements, string handling etc. are much easier than a declarative language like yaml, it's also consistent/portable across vendors/services, whereas there's no standard for yaml.

Cake is released as open-source on GitHub. It is actively maintained with more than 200 contributors. According to the NuGet package manager statistics, the new version had over 35,000 daily downloads, placing Cake as one of the most popular .NET libraries.

About the Author

Rate this Article

Adoption
Style

BT