CodeCake/Cake.Embedded: a "code based" approach to Cake-build
See original GitHub issueI actually have an idea in mind. A strange one may be… but an interesting one I believe. I’m a little bit reluctant to express it before having gained credibility from all of you. But… well… let’s go!
The idea is named “CodeCake”. It is an alternative to scripting (I can imagine how difficult it could be for guys who designed a project around scripting to consider this approach!). It relies on a cs project in the solution that can be a console application and even a GUI application (winForm or WPF or whatever activated by a -gui (or -ui) switch.
The scripts are replaced with classes with a default ctor: below is a (working) example from the POC I’m working on:
class Build : CodeCakeHost
{
public Build()
{
var configuration = Cake.Argument( "configuration", "Release" );
// Define directories.
var buildDir = Cake.Directory( "./src/Example/bin" ) + Cake.Directory( configuration );
Task( "Clean" )
.Does( () =>
{
Cake.CleanDirectory( buildDir );
} );
Task( "Restore-NuGet-Packages" )
.IsDependentOn( "Clean" )
.Does( () =>
{
Cake.NuGetRestore( "./src/Example.sln" );
} );
Task( "Build" )
.IsDependentOn( "Restore-NuGet-Packages" )
.Does( () =>
{
Cake.MSBuild( "./src/Example.sln", new MSBuildSettings()
.UseToolVersion( MSBuildToolVersion.NET45 )
.SetVerbosity( Verbosity.Minimal )
.SetConfiguration( configuration ) );
} );
Task( "Run-Unit-Tests" )
.IsDependentOn( "Build" )
.Does( () =>
{
Cake.XUnit2( "./src/**/bin/" + configuration + "/*.Tests.dll" );
} );
Task( "Default" )
.IsDependentOn( "Run-Unit-Tests" );
}
}
There is really nothing more to it (except the required using namespaces): the Cake
that appears here is a property exposed by the base CodeCakeHost class that is actually just an alias to the Context
property (extension methods apply and intellisense magics operates).
The overall process of working with CodeCake is the following:
- Create a new project from a VS Project CodeCake template.
- This project has one sample Build script that you can edit with all the intellisense support you can dream of.
- This application depends solely on NuGet packages:
- Cake.Core
- CodeCake
- Cake.Common
- NuGet.CommandLine
- Any other extension packages you may need.
- To trigger a release, just compile and run it…
- …and this is where the -gui switch may come into play: a user interface can be scaffolded from:
- the existing CodeCakeHost classes in the project and their expected arguments/configurations.
- any helpers/utilities (automatically registered by reflection) offered in any NuGet extension packages.
- …and this is where the -gui switch may come into play: a user interface can be scaffolded from:
- For unattended builds (CI), the first thing to do is to MSBuild the CodeCake project and runs it (or one of its “scripts”). (And, yes, I know, there is still a small chicken-and-eggs issue here to restore the NuGet packages…)
Note: To honor the “scripting promise”, simply install the Cake.Scripting NuGet package in the CodeCake project and (Oh! Magic!) you can use:
Cake.CakeExecuteExpression(
"Information(\"Hello {0}!\", Argument<string>(\"name\"));",
new CakeSettings {
ToolPath="./Cake.exe" ,
Arguments = new Dictionary<string, string>{{"name", "World"}}
});
or
Cake.CakeExecuteScript("./helloworld.cake");
from your build “scripts”.
This is it. My long term goal is to provide a very simple (with no coupling to the IDE or the system - NuGet packages only) way to build/deploy/distribute/use a potentially unlimited of tools for the developer (for instance the classical “licence header processor”, you need it but do not want to deploy a vsix for such little things).
Issue Analytics
- State:
- Created 8 years ago
- Comments:19 (15 by maintainers)
Top GitHub Comments
Yip, yip, yip. We would welcome any feedback that you have on it.
@ryangribble I can’t say much at the moment, but if you have some patience I will have a surprise for you in a couple of weeks that will solve your problem 😄