![]() |
VOOZH | about |
dotnet add package Cake.Generator --version 6.2.0
NuGet\Install-Package Cake.Generator -Version 6.2.0
<PackageReference Include="Cake.Generator" Version="6.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageVersion Include="Cake.Generator" Version="6.2.0" />Directory.Packages.props
<PackageReference Include="Cake.Generator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>Project file
paket add Cake.Generator --version 6.2.0
#r "nuget: Cake.Generator, 6.2.0"
#:package Cake.Generator@6.2.0
#addin nuget:?package=Cake.Generator&version=6.2.0Install as a Cake Addin
#tool nuget:?package=Cake.Generator&version=6.2.0Install as a Cake Tool
| Package | Latest Release | Prerelease |
|---|---|---|
| 👁 NuGet |
||
| 👁 NuGet |
||
| 👁 NuGet |
A .NET source generator that creates proxy methods for Cake build system extensions, eliminating the need to pass ICakeContext explicitly.
This source generator scans referenced assemblies for static extension methods that have:
System.Runtime.CompilerServices.ExtensionAttributeCake.Core.Annotations.CakeMethodAliasAttribute or Cake.Core.Annotations.CakePropertyAliasAttributeCake.Core.ICakeContextIt then generates proxy methods in a partial static class named Program that:
ICakeContext parameterContext property instead/// <summary>
/// Writes an error message to the log using the specified format information.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="format">The format.</param>
/// <param name="args">The arguments.</param>
/// <example>
/// <code>
/// Error("Hello {0}! Today is an {1:dddd}", "World", DateTime.Now);
/// </code>
/// </example>
[CakeMethodAlias]
public static void Error(this ICakeContext context, string format, params object[] args)
/// <summary>
/// Writes an error message to the log using the specified format information.
/// </summary>
/// <param name="format">The format.</param>
/// <param name="args">The arguments.</param>
/// <example>
/// <code>
/// Error("Hello {0}! Today is an {1:dddd}", "World", DateTime.Now);
/// </code>
/// </example>
public static void Error(string format, params object[] args)
=> Context.Error(format, args);
Cake.Generator/
├── src/
│ ├── Cake.Generator.Core/ # Source generator implementation
│ │ ├── CakeGenerator.cs
│ │ ├── CakeGenerator.*.cs # Partial generator classes
│ │ └── Cake.Generator.Core.csproj
│ ├── Cake.Generator/ # Meta project with default dependencies
│ │ └── Cake.Generator.csproj
│ ├── Cake.Generator.TestApp/ # Test application (used to build project)
│ │ ├── Program.cs
│ │ └── Cake.Generator.TestApp.csproj
│ ├── Cake.Generator.Core.Tests/ # Unit tests
│ │ └── Cake.Generator.Core.Tests.csproj
│ ├── Cake.Sdk/ # .NET SDK for Cake
│ │ └── Cake.Sdk.csproj
│ ├── Cake.Template/ # Project template for Cake
│ │ └── Cake.Template.csproj
│ └── Cake.Generator.slnx # Solution file (slnx format)
└── README.md
<ItemGroup>
<PackageReference Include="Cake.Generator" Version="1.0.0" />
</ItemGroup>
This will automatically include:
The generator creates a partial static Program class with generated methods that use an internal Context property, eliminating the need to pass ICakeContext explicitly.
Program.cs (Top-Level Statements)With the generator, your Program.cs can be simplified significantly, leveraging top-level statements and the automatically generated alias methods:
Task("Build")
.Does(() => Information("Build"));
Task("Default")
.IsDependentOn("Build");
await RunTargetAsync(target);
Any Cake addin can be added as a PackageReference and its alias proxies will be generated automatically, example:
<ItemGroup>
<PackageReference Include="Cake.Twitter" Version="5.0.0.0" />
</ItemGroup>
The generator will scan the addin assembly and create proxy methods for all discovered Cake method and property aliases, making them available as static methods without requiring explicit ICakeContext parameters.
The generator now supports Cake modules with automatic registration. Modules referenced in your project will have their method and property aliases automatically discovered and proxy methods generated, just like regular addins. This includes both NuGet package modules and local module assemblies, example:
<ItemGroup>
<PackageReference Include="Cake.BuildSystems.Module" Version="7.1.0" />
</ItemGroup>
The generator creates a partial Program class that allows you to register your own services to the IoC container. Simply implement the RegisterServices partial method:
public static partial class Program
{
static partial void RegisterServices(IServiceCollection services)
{
// Register your services here
services.AddSingleton<IMyService, MyService>();
services.AddTransient<IAnotherService, AnotherService>();
services.AddScoped<IScopedService, ScopedService>();
}
}
Services can be resolved from the IoC container using the static ServiceProvider property. Here's how to use it in your tasks:
Task("MyTask")
.Does(() => {
// Resolve a service
var myService = ServiceProvider.GetRequiredService<IMyService>();
// Use the service
myService.DoSomething();
// You can also resolve multiple services
var anotherService = ServiceProvider.GetRequiredService<IAnotherService>();
anotherService.Process();
});
The ServiceProvider is available throughout your build script, making it easy to access your registered services wherever needed.
The generator now supports multiple main entry points and IoC container integration with the script host, enabling more modular and organized build scripts.
You can define multiple entry points using Main_* prefixed methods that are automatically discovered and executed:
// Program.Main.cs
public static partial class Program
{
private static void Main_One()
{
Task(nameof(Main_One))
.IsDependeeOf("Clean")
.Does(() => Information("Hello from Main_One"));
}
private static void Main_Two()
{
Task(nameof(Main_Two))
.IsDependeeOf("Clean")
.Does(() => Information("Hello from Main_Two"));
}
}
You can register actions that interact with the script host through the IoC container:
// Program.RegisterServices.cs
static partial void RegisterServices(IServiceCollection services)
{
services.AddSingleton(new Action<IScriptHost>(
host => host.Task("IOC-Task")
.IsDependeeOf("Clean")
.Does(() => Information("Hello from IOC-Task"))));
}
This enables dynamic task creation and more flexible build script organization across multiple files.
The following constants are automatically generated and available in your Cake script:
| Constant | Description |
|---|---|
CakeGeneratorDate |
The UTC date and time when the aliases were generated (format: yyyy-MM-dd HH:mm:ssZ) |
CakeGeneratorVersion |
The version of Cake.Generator.Core used to generate the aliases |
CakeGeneratorInformationalVersion |
The full informational version of Cake.Generator.Core, including build metadata |
CakeGeneratorNuGetVersion |
The NuGet package version of Cake.Generator.Core |
These constants are useful for version tracking and debugging purposes in your Cake scripts.
Here's an example of how to use these constants in your Cake script:
Task("Version-Info")
.Does(() =>
{
Information("Generated with Cake.Generator.Core version: {0}", CakeGeneratorVersion);
Information("Generation date: {0}", CakeGeneratorDate);
});
This will output the version information when you run the Version-Info task.
The generator provides methods to install tools that can be used in your Cake script. Here are examples of how to use them:
// Install a single tool using a package reference string
InstallTool("dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=5.12.0");
// Install multiple tools at once
InstallTools(
"dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=5.12.0",
"dotnet:https://api.nuget.org/v3/index.json?package=GitReleaseManager.Tool&version=0.20.0"
);
The InstallTool and InstallTools methods return the paths where the tools were installed, which can be useful for verification or direct tool execution.
Tools installed using these methods are automatically registered with Cake's tool resolution system, meaning you can use them directly in your tasks without specifying their full paths. For example:
Task("Use-Registered-Tools")
.Does(() =>
{
// GitVersion is automatically available in PATH
var version = GitVersion();
// GitReleaseManager is automatically available
GitReleaseManagerCreate("token", "owner", "repo");
});
ref, out, in, params)CakeMethodAlias and CakePropertyAlias attributesCakeNamespaceImport attribute for importing global static namespacesProgram class with no namespaceMain_* method discovery# Build the source generator
dotnet build src/Cake.Generator.Core/Cake.Generator.Core.csproj
# Build the meta package
dotnet build src/Cake.Generator/Cake.Generator.csproj
# Build and test the complete solution
dotnet test src/Cake.Generator.slnx
# Run the test application
dotnet run --project src/Cake.Generator.TestApp/Cake.Generator.TestApp.csproj
MIT License - see LICENSE file for details.
Learn more about Target Frameworks and .NET Standard.
Showing the top 1 NuGet packages that depend on Cake.Generator:
| Package | Downloads |
|---|---|
|
Cake.Sdk
A custom SDK that provides a convenient way to create Cake projects with minimal configuration. Automatically sets up common properties and references the Cake.Generator for source generation capabilities. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 6.2.0 | 22,094 | 5/22/2026 |
| 6.1.1 | 64,916 | 3/2/2026 |
| 6.1.0 | 4,128 | 3/1/2026 |
| 6.0.0 | 68,728 | 11/11/2025 |
| 5.1.25296.94-beta | 390 | 10/23/2025 |
| 5.1.25292.90-beta | 192 | 10/19/2025 |
| 5.1.25277.88-beta | 326 | 10/4/2025 |
| 5.0.25276.86-beta | 134 | 10/3/2025 |
| 5.0.25257.82-beta | 301 | 9/14/2025 |
| 5.0.25253.70-beta | 211 | 9/10/2025 |
| 5.0.25225.53-beta | 306 | 8/13/2025 |
| 5.0.25225.51-beta | 180 | 8/13/2025 |
| 5.0.25198.49-beta | 301 | 7/17/2025 |