Who Wants Cake?!

I’ve been learning and trying out new build systems in .NET recently and decided to give Cake a sample. (See what I did there?)

First Impressions

Right away I liked how the scripts look and feel. This is quite important to me and one of the reasons I dislike scripting things in Powershell. Powershell is more difficult for me to read and understand than I would like. I believe it’s largely due to the common coding styles, but that’s my problem.

Here’s a sample script:

var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var buildDir = Directory("./src/Example/bin") + Directory(configuration);

Task("Clean")
  .Does(() => {
    CleanDirectory(buildDir);
});

Task("Restore-NuGet-Packages")
  .IsDependentOn("Clean")
  .Does(() => {
    NuGetRestore("./src/Example.sln");
});

Task("Build")
  .IsDependentOn("Restore-NuGet-Packages")
  .Does(() => {
    MSBuild("./src/Example.sln", settings =>
      settings.SetConfiguration(configuration));
});

Task("Default")
  .IsDependentOn("Build");

RunTarget(target);

To me (and possibly because I write C# nearly every day) this is very readable and nice to look at.

Tools

There are loads of tools out of the box, but a couple more that I needed. I was able to get Fixie into the v0.5.0 release, so that was nice. The other is RoundhousE, which should be coming soon!

Contributing

Many Kudos to Patrik for maintaining a very clean and intuitive codebase! Everything is well thought out, in the right place, and easy to understand and follow. If you want to fix a bug or add a feature to this project, it won’t be hard. In fact, it will probably be a pleasure! Additionally, the issues on GitHub are a great place to ask questions, request features, or submit bugs. You’ll likely get a response from Patrik or somebody else the same day; as a maintainer of other open source projects, I wish I was that good.

All of these reasons make this a very nice project to work on if you’re looking to get more into open source. There are even some Up For Grabs Cake issues you could work on today!

About Chris Missal

Oh hey, I'm a Senior Consultant for Headspring in Austin, TX. I've been working in software professionally since 2006 and I really, really love it. I'm mostly in the Microsoft world, but enjoy building computer things of all sorts (to be vague). When I'm not slinging code, I'm probably out and about slinging discs, bowling balls, or good beer with great friends.
This entry was posted in .NET, C#, Continuous Integration, Deployment, Open Source and tagged , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Get Naked! :) https://github.com/yevhen/Nake

    Seriously, try it! Instead of mimicking old and suffering Rake-ish style DSL, I tried to utilize Roslyn to its full potential. Only Nake has such minimal, bare metal DSL, which is just plain method-based C#, while still guaranteeing “run once” semantics like any other build automation tool.

    Rake was built on top of closures (blocks), since it was the only way to go. With Roslyn – we can do much better than that ;)

  • zhuravl

    I hate to ask that, but what about gulp? It works pretty well with msbuild and everything. I’m trying to understand benefits for consumer.

    • It’s all about preference to me. If you like writing build scripts in JavaScript, no problem, use Gulp. If you prefer C#, use Cake. I actually like trying several, expect a post on FAKE soon. I have used Gulp and I do like it, it’s nice.

      If you’re on a team that does a lot of web development, I think Gulp is a great fit. You likely write JavaScript every day, so it’s a great choice. However, if you’re on a team that is building messaging systems that require little to no front-end, then Cake may be a better fit for your team since it’s in a language that you’re already using.

      I’m not promoting Cake as “the best” or trying to convince anybody to use it. I just think it’s a good project and a great community around and wanted to share.

      • Sam Wise

        I was actually going to you ask you about FAKE but since you are going to blog about it anyway, can you take some time to articulate what you found different/better/worse with FAKE compared to CAKE, MSBuild, Gulp, etc.?

  • AlexanderTank

    Where do you write those scripts (in VS)? Do you still have Intellisense available?

    • VSCode supports .csx. Just place empty project.json file in the same directory where csx files are located. Then use “Open Directory” command

      • Unfortunately, Cake doesn’t use .csx files — its files are *.cake.
        It’s not actually based on ScriptCs, but rather a more direct usage of Roslyn.

        • You can use either a .cake file, or a .csx file. In fact I have only used csx so far.

          • Oh that’s good to know, thanks Chris!