question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CodeCake/Cake.Embedded: a "code based" approach to Cake-build

See original GitHub issue

I 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.
  • 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:closed
  • Created 8 years ago
  • Comments:19 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
gep13commented, Sep 1, 2016

@ryangribble said… I’ll definitely check out frosting - is this the surprise you were referring to?

Yip, yip, yip. We would welcome any feedback that you have on it.

1reaction
patriksvenssoncommented, Aug 23, 2016

@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 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found