Cake v3.0.0 released

Published
08 November 2022
Category
Release Notes
Author
devlead

Version 3.0.0 of Cake has been released. Take it for a spin and give us feedback on our discussion board.

This release includes several new features, improvements and bug fixes to both Cake Scripting and Cake Frosting since the Cake v2.3.0 release! 🚀 🍰

Highlights of this release

  • .NET 7 Support & C#11 Support
  • TaskOf<T>
  • Multiple target support
  • Improved build providers
  • Addin recommended Cake version set to 3.0.0

Breaking changes

Being a major release we've taken the opportunity to remove obsolete aliases and members, i.e. DotNetCore* aliases were obsoleted and replaced by DotNet* aliases in Cake 2.0 and are now removed with 3.0.0.

Cake itself will no longer run on .NET Core 3.1 or .NET 5, but Cake will continue to support the building of .NET Framework projects, as well as projects targeting .NET 5.0 or older.

The supported platform matrix for Cake 3.0.0 will look like this:

Runner .NET 7 .NET 6
Cake .NET Tool
Cake Frosting

.NET 7 Support & C# 11 Support

Cake now fully supports running on .NET 7, and with this C# 11, which means you can take advantage of the latest framework, runtime, and language improvements.

TaskOf<T>

For scripting, a new TaskOf<T> method has been introduced to simplify when working with shared typed data contexts, where one only needs to specify the type parameter once and only get task methods that are relevant, example:

public record BuildData(bool Initialized);

Setup(ctx => new BuildData(true));

TaskOf<BuildData>("TaskOfT")
    .Description("Very typed task")
    .WithCriteria((context, data) => data.Initialized)
    .Does((context, data) => context.Information("Initialized: {0}.", data.Initialized))
    .Does(async (context, data) => await /* async work*/)
    .DoesForEach(
        (data, context) => new [] { data.Initialized },
        (data, item, context) => context.Information("Item: {0}, Initialized: {1}.", item, data.Initialized)
    )
    .DoesForEach(
        new [] { true, false },
        (data, item, context) => context.Information("Item: {0}, Initialized: {1}.", item, data.Initialized)
    );

RunTarget("TaskOfT");

Multiple target support

Also for scripting, a new RunTargets(IEnumerable<string> targets) method is now available. It'll let you specify multiple targets as the entry point in Cake's dependency graph to execute, where dependencies and dependency order is still respected. For example calling script below with dotnet cake --target="A" --target="B"

Task("A")
    .Does(() => { /* do stuff */ });

Task("B")
    .IsDependentOn("C")
    .Does(() => { /* do stuff */ });

Task("C")
    .Does(() => { /* do stuff */ });

Task("Default");

RunTargets(Arguments<string>("target", new []{ "Default" }));

will generate the following execution

========================================
A
========================================

========================================
C
========================================

========================================
B
========================================

Task                          Duration
--------------------------------------------------
A                             00:00:00.0028166
C                             00:00:00.0006761
B                             00:00:00.0006161
--------------------------------------------------
Total:                        00:00:00.0041088

Improved build providers

Cake 3.0.0 comes with a few improvements to build providers i.e.

  • GitHub Actions
    • SetStepSummary Command
    • SetOutputParameter Command
    • Workflow commands
  • TeamCity
    • Build status message
    • Statistics
  • GitLab
    • SetEnvironmentVariable Command
    • CI runner tags improvements

We've now set the recommended version of Cake.Core for addins to target to 3.0.0.

This won't break the build, but you might see warnings like below when addins or modules are loaded.

The assembly 'Cake.Twitter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' 
is referencing an older version of Cake.Core (2.0.0). 
For best compatibility it should target Cake.Core version 3.0.0.

Contributors

This release was made possible thanks to the Cake team and the contribution of these awesome members of the Cake community listed below:

Full details of everything that was included in this release can be seen below.

Issues

As part of this release we had 45 issues closed.

Breaking change

  • #4046 Add typed data context CakeTaskBuilder.Finally overload.
  • #4000 Remove obsolete CakeEngine Setup/Teardown events.
  • #3997 Remove obsolete Logger property from DotNetTestSettings.
  • #3991 Remove Obsolete DotNetCore aliases.
  • #3972 Remove .NET Core 3.1 TFM.
  • #3969 Update Spectre.Console to 0.45.0.
  • #3949 Remove .NET 5 TFM.
  • #3946 Access to ITaskSetupContext in Frosting.
  • #3867 Rename WindowsFact to WindowsFactAttribute to follow best practices.
  • #3722 DotNetCore -> DotNet Rename Missed Objects.

Feature

  • #4047 Add typed CakeTaskBuilder / TaskOf() to easier work with typed data context.
  • #4028 Add GitLab CI SetEnvironmentVariable Command.
  • #4019 Add support for TeamCity build status message.
  • #4018 Add Support For TeamCity Statistics.
  • #4011 Add GitHub Actions SetStepSummary Command.
  • #4009 Add GitHub Actions SetOutputParameter Command.
  • #3950 Add .NET 7 Support.
  • #3328 Frosting: Support criteria description.
  • #2863 Add support for GitHub Action workflow commands.
  • #2470 Call multiple tasks from CLI and pass them to RunTarget.
  • #1146 Add OutputDirectory property for Chocolatey Aliases.

Improvement

  • #4060 Update Microsoft.NETCore.Platforms to 7.0.0.
  • #4059 Update System.Reflection.Metadata to 7.0.0.
  • #4058 Update System.Collections.Immutable to 7.0.0.
  • #4057 Update Microsoft.Extensions.DependencyInjection to 7.0.0.
  • #4055 Add column to summary to include skip reason.
  • #4052 Update Basic.Reference.Assemblies.* to 1.4.1.
  • #4050 Overhaul Chocolatey Cake aliases.
  • #4044 Overload missing for IsDependeeOf accepting a CakeTaskBuilder object.
  • #4038 Add missing MSBuildSettings to DotNetRunSettings.
  • #4036 Add missing MSBuildSettings to DotNetTestSettings.
  • #4032 Add additional settings for ILMerge.
  • #4020 Update Basic.Reference.Assemblies.* to 1.4.0.
  • #4016 Update Microsoft.CodeAnalysis.CSharp.Scripting to 4.4.0-4.final.
  • #4006 Add missing GitVersion command line options.
  • #3124 EscapedBranchName is not supported by GitVersion.CommandLine.

Documentation

  • #4023 Update supported versions of Cake.

Bug

  • #4034 DotNetMSBuildSettings ArgumentCustomization is not called with all DotNet* aliases.
  • #4030 GitLab CI runner tags are not split correctly.