FAKE It Till You Make It

I’ve been studying build systems in .NET recently. I believe that automation is one of the most important pieces to any successful software project. Previously I wrote about Cake and how I liked the ease of use as well as how nice it was to contribute to the project. I mentioned in the comments of that post that I would be blogging about FAKE as well, and this post is that.

FAKE isn’t anything new. In fact, it’s been around for well over 5 years. Scott Hanselman had a really good post about it back in March of last year. If you’ve been keeping up, this will be nothing new, but for the readers that haven’t been following the activity, I hope my thoughts about it will be helpful to you.

Last week I presented at Headspring on this same topic with Patrick. Patrick is a fan of FAKE and I won’t speak for him, but I’m fairly certain he agrees with me in that I’d like to see more people and teams using it. There were two objectives to the presentation:

  1. Introduce FAKE to those that aren’t familiar.
  2. Convince people to give it a shot.

Now I can’t make you or my coworkers use it; that’s not the point. I just want to show you what you may be missing and let you choose your own build strategy from here on. I like FAKE and think it’s the best solution to the build and automation problem we face in .NET every day. I’d like to go over a few reasons why I think so. Before I do that, I’m going to talk about a few reasons why you shouldn’t use it.

Why You Shouldn’t be Using FAKE

You’re a Pro at PowerShell

You can whip together some PS code in no time. You never forget the equality operators, you even know the commands for file manipulation without having to Google them. That’s awesome and I wish I had the same skills as you. PowerShell is a very powerful language and can do a ton of amazing things! I don’t want to take anything away from PowerShell, but I don’t spend a lot of time in it. Because of this, I’m not nearly as efficient when writing it. If you have no problems with these things, this post might not be for you, sorry I can’t give you much to read about.

If, however, you have the same problems I have, maybe you should keep going.

You Don’t Want to Write F

The assumption that you need to be proficient in F# to use FAKE is a false one. I hear this often and I don’t know where it came from, and I can only easily assume why. The good thing about FAKE is that it doesn’t require a deep understanding of F#. It’s a DSL built on F# and writing FAKE is much different, I’ll say easier, than writing F#.

You’ve Adopted Gulp/Grunt

You might not want to give FAKE a try because you’re already invested in using JavaScript as your build language. I love JavaScript, don’t get me wrong, but these approaches require a bit more setup than your standard .NET build script. You need some extra dependencies that fall outside the default stack. (Yes, I realize that Gulp/Grunt tasks are now built in to Visual Studio. I’m not sure how I feel about this yet.) FAKE can be downloaded via NuGet, and you are off to the races. Sometimes a JavaScript dependency isn’t always ideal for a project because it’s possible that the only JS is in the build. You’re not really gaining anything at this point.

Why You Should be Using FAKE

It’s Best of Breed in .NET

There are several build tools out there, but through all the ones I’ve used, FAKE is winning. It has the biggest community around it, most built-in features (that I’m aware of), it’s still actively developed and maintained, and runs on Linux.

The Help is Fantastic

When you need assistance, there are a lot of options available: great documentation, terrific responses on GitHub, and even Google and Stackoverflow are helpful. Oh, and let’s not forget the entire F# community!

Faster and Easier

I’m still no veteran when it comes to writing FAKE scripts, but I can honestly say that it’s far more of an efficient use of my time than any other build tool I’ve used. With all the “Helpers” (over 100 in fact) there’s not much that you have to write on your own. You’re literally just putting building blocks together in the order and direction you want them.

A Sample Script

Anyway, on with the sample code! This tiny little snippet comes directly from the FAKE site, and I’ll leave it with you and let you browse on over there to check out more samples since that won’t get out of date as fast as this may.

#r "tools/FAKE/tools/FakeLib.dll" // include Fake lib
open Fake


Target "Test" (fun _ ->
    trace "Testing stuff..."
)

Target "Deploy" (fun _ ->
    trace "Heavy deploy action"
)

"Test"            // define the dependencies
   ==> "Deploy"

Run "Deploy"

Closing Thoughts

Like other FAKE fans, it’s one of those “why wasn’t I using this long ago?!” thoughts. I could keep going on, but I’ll let you check it out and form your own opinions. As somebody who doesn’t like to change things up too often, I’m VERY glad I’ve made the switch from PowerShell (in my case) to FAKE.

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, Continuous Integration, Deployment, F#, Open Source and tagged , . Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • I rather like F#, but I find the FAKE syntax really weird and unnatural, with all those obscure custom operators. You can’t really understand a FAKE script before you read some documentation, because you can’t guess what the “!!” or “++” or “==>” operators mean.

    I much prefer Cake (which I discovered on your blog). It feels like plain old C#, and use named methods rather than operators, which make it much easier to read, even to the untrained eye.

  • gleb Chermennov

    Have you considered Rake+albacore?

    • I did briefly (albeit many years ago) and couldn’t really get into it. Like gulp requiring node and npm, I don’t like those extra dependencies. Since FAKE has tons of integrations and works without extras, I prefer it to those options.

  • dave falkner

    I wonder if anyone has a nicely compiled list of 3rd party tools around which FAKE provides this nice English-like DSL abstraction? (Such as MSBuild, NUnit, AssemblyInfo.cs, etc.) I have been very impressed with expanse of supported tools, but only discovered many of them by reading through the FAKE source code.

  • gilligan_MH

    ok now write about how to integrate FAKE with Octopus Deploy :-D

  • Chris, having worked with both FAKE and Cake now, what’s your take on how they stack up against each other?
    Do you see yourself continuing to use and contribute to Cake, or is it gonna be all FAKE for you going forward?

    • FAKE is more mature than Cake (at the moment), so it’s still going to remain my first choice. I still plan on contributing to Cake to move it forward so that it’s just as powerful as FAKE. Once it gets to that point, I’ll have to re-evaluate. :)

      • That sounds like a solid strategy to me. Glad to hear you’ll continue to contribute!