![]() |
VOOZH | about |
dotnet add package Cake.Console --version 5.0.0
NuGet\Install-Package Cake.Console -Version 5.0.0
<PackageReference Include="Cake.Console" Version="5.0.0" />
<PackageVersion Include="Cake.Console" Version="5.0.0" />Directory.Packages.props
<PackageReference Include="Cake.Console" />Project file
paket add Cake.Console --version 5.0.0
#r "nuget: Cake.Console, 5.0.0"
#:package Cake.Console@5.0.0
#addin nuget:?package=Cake.Console&version=5.0.0Install as a Cake Addin
#tool nuget:?package=Cake.Console&version=5.0.0Install as a Cake Tool
Cake scripts, but in a Console app.
An alternative to Cake.Frosting
https://blog.pitermarx.com/2021/09/presenting-cake-console/
Create a new project referencing Cake.Console. It will look something like this
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Cake.Console" Version="4.0.0" />
</ItemGroup>
</Project>
Add a single Program.cs file with the code. Take advantage of top-level statements.
There are 2 ways of using Cake.Console:
var host = new CakeHostBuilder().BuildHost(args);
host.Setup(() => { do something });
host.Task("TaskName").Does(c => c.Information("Hello"));
host.RunTarget(host.Context.Arguments.GetArgument("target"));
new CakeHostBuilder()
.WorkingDirectory<WorkingDirectory>()
.ContextData<BuildData>()
.RegisterTasks<CakeTasks>()
.InstallNugetTool("NuGet.CommandLine", "5.9.1")
.InstallDotnetTool("GitVersion.Tool", "5.7.0")
.RunCakeCli(args);
In this case, we dont have access to the host, so we need to define the build with the 4 extensions that come with Cake.Console:
Here we can use a class that has the interface IWorkingDirectory and implements the string WorkingDirectory property.
The class can receive in the constructor any part of the cake infrastructure (ICakeContext, ICakeLog, ICakeArguments, ICakeConfiguration...)
Here we can use a class that has the interface ICakeTasks.
The class can receive in the constructor any part of the cake infrastructure (ICakeContext, ICakeLog, ICakeArguments, ICakeConfiguration...)
All the methods that have the signature void Name(CakeTaskBuilder builder) will be called, and the name of the method will be the name of the task.
Here we can use any class that will then be available for use in the task's definitions.
Given a package name and a version, installs a nuget package or a dotnet tool as a Cake tool
Putting it all together
using Cake.Common.Diagnostics;
using Cake.Console;
using Cake.Core;
new CakeHostBuilder()
.WorkingDirectory<WorkingDir>()
.ContextData<ContextData>()
.RegisterTasks<CakeTasks>()
.InstallNugetTool("xunit.runner.console", "2.4.1")
.RunCakeCli(args);
record WorkingDir(string WorkingDirectory = ".") : IWorkingDirectory;
class ContextData(ICakeArguments args)
{
public string SomeVeryImportantData { get; set; } =
args.HasArgument("tone-down") ? "Cake is pretty good..." : "Cake is awesome!";
}
class CakeTasks(ICakeContext ctx) : ICakeTasks
{
public static void TaskName(CakeTaskBuilder b) => b
.Description("Some task")
.Does(c => c.Information("Something"));
public void AnotherTask(CakeTaskBuilder b) => b
.IsDependentOn(nameof(TaskName))
.Does<ContextData>(data => ctx.Information(data.SomeVeryImportantData));
}
It is also possible to use dotnet-script. Thanks @badsim See an example in ./dotnet-script/test.csx
dotnet script --isolated-load-context ./dotnet-script/test.csx --target=test
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.