Cake v2.3.0 released

Published
14 October 2022
Category
Release Notes
Author
devlead

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

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

Highlights of this release

  • Better global script cache support
  • .NET CLI workload aliases
  • Command aliases

Better global script cache support

Script cache introduced in v2.2.0 has been improved to support parallel builds and multiple versions of the same script even when the cache is in a globally shared location.

Command aliases

While Cake support many tools out of the box or via the many available addins, there will always be tools or scenarios where you need to execute a custom tool, while this is already possible using the StartProcess alias, you need to write custom code for things like i.e. tool resolution, exit code handling, and handling command output.

To solve this we've in this release introduced the Command alias which fills the gap in-between StartProcess and the out-of-the-box typed aliases, it lets you benefit from Cake's built-in tool resolution making it easier to support tools with different executables i.e. Posix/Windows or installed using tool directive. It will default fail the build on non-zero exit codes, and also provides more convenient access to standard output/error. A few Command alias examples below, and several more in the features pull request.

Executing tool using implicit ProcessArgumentBuilder

Command(
    new []{ "dotnet", "dotnet.exe"},
    "--version"
);

Executing tool using ProcessArgumentBuilder

#tool dotnet:?package=DPI&version=2022.8.21.54
Command(
    new []{ "dpi", "dpi.exe"},
    new ProcessArgumentBuilder()
        .Append("nuget")
        .AppendQuoted(Context.Environment.WorkingDirectory.FullPath)
        .AppendSwitch("--output", " ", "TABLE")
        .Append("analyze")
);

Executing tool specifying expected exit code

Command(
    new []{ "dotnet", "dotnet.exe"},
    expectedExitCode: -2147450751
);

Executing tool using settings customization

Command(
    new []{ "dotnet", "dotnet.exe"},
    settingsCustomization: settings => settings
                                            .WithToolName(".NET tool")
                                            .WithExpectedExitCode(1)
                                            .WithArgumentCustomization(args => args.Append("tool"))
);

Reusable tools settings i.e. created in setup.

#tool dotnet:?package=DPI&version=2022.8.21.54
// Reusable tools settings i.e. created in setup.
var settings = new CommandSettings {
        ToolName = "DPI",
        ToolExecutableNames =  new []{ "dpi", "dpi.exe"},
     };

// Example with ProcessArgumentBuilder
Command(
    settings,
    new ProcessArgumentBuilder()
         .Append("nuget")
         .AppendQuoted(Context.Environment.WorkingDirectory.FullPath)
         .AppendSwitch("--output", " ", "TABLE")
         .Append("analyze")
);

// Example with implicit ProcessArgumentBuilder
Command(
     settings,
     $"nuget --output TABLE analyze"
);

Handling standard output

using System.Text.Json.Serialization;
using System.Text.Json;
#tool dotnet:?package=DPI&version=2022.8.21.54

// Example with ProcessArgumentBuilder
var exitCode = Command(
    new []{ "dpi", "dpi.exe"},
    out var standardOutput,
    new ProcessArgumentBuilder()
         .Append("nuget")
         .AppendQuoted(Context.Environment.WorkingDirectory.FullPath)
         .AppendSwitch("--output", " ", "JSON")
         .Append("analyze")
);

var packageReferences =  JsonSerializer.Deserialize<DPIPackageReference[]>(
    standardOutput
);

// Record used in example above
public record DPIPackageReference(
    [property: JsonPropertyName("source")]
    string Source,
    [property: JsonPropertyName("sourceType")]
    string SourceType,
    [property: JsonPropertyName("packageId")]
    string PackageId,
    [property: JsonPropertyName("version")]
    string Version
);

Handling standard error

// Example with ProcessArgumentBuilder
var exitCode = Command(
    new []{ "dotnet", "dotnet.exe" },
    out var standardOutput,
    out var standardError,
    new ProcessArgumentBuilder()
        .Append("tool"),
    expectedExitCode:1
);

Verbose("Exit code: {0}", exitCode);
Information("Output: {0}", standardOutput);
Error("Error: {0}", standardError);

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 41 issues closed.

Feature

  • #3947 Easier Way to Read Process Output?.
  • #3916 GitVersion: Add ShortSha property.
  • #3487 Add alias for dotnet workload update command.
  • #3486 Add alias for dotnet workload uninstall command.
  • #3484 Add alias for dotnet workload restore command.
  • #3483 Add alias for dotnet workload repair command.
  • #3482 Add alias for dotnet workload list command.

Improvement

  • #3978 Microsoft.Extensions.DependencyInjection to 6.0.1.
  • #3976 Update NuGet.* to 6.3.1.
  • #3970 Update Basic.Reference.Assemblies.* to 1.3.0.
  • #3965 Update Microsoft.CodeAnalysis.CSharp.Scripting to 4.3.1.
  • #3956 Extensibility issue - CakeEngineActions is internal.
  • #3933 Update NuGet.* to 6.3.0.
  • #3920 Update Microsoft.NETCore.Platforms to 6.0.5.
  • #3909 Update Autofac to 6.4.0.
  • #3901 Update Microsoft.CodeAnalysis.CSharp.Scripting to 4.2.0.
  • #3899 Microsoft.NETCore.Platforms to 6.0.4.
  • #3897 Update NuGet.* to 6.2.1.
  • #3890 Update NuGet.* to 6.2.0.
  • #3880 Better support global script cache.
  • #2953 Allow setting MSBuild target via MSBuildSettings using a string.
  • #2591 Extensibility issue - CakeTaskBuilder is sealed and CakeTaskBuilder(CakeTask task) is internal. .

Bug

  • #3931 Cake fails to load native libraries on Ubuntu 22.04.
  • #3894 Guard against null Console instance on InfoFeature.
  • #3879 Build script caching throws after running dry-run on non-changed Cake script.
  • #3878 OpenCover filters should be case sensitive.
  • #1852 Incorrect escaping of semi-colon in property values for MS Build.