Wednesday, April 3, 2013

Introducing FAKE boot workflow

FAKE is a tool to automate your builds with F# scripts. Use the newly available FAKE boot workflow to get started quickly, automatically reference packages, and plug in your own build logic from NuGet.

Starting from FAKE 2.1.173-alpha FAKE includes a new "boot" workflow. Let us walk through it. First, make a new folder (I am using PowerShell, but you can do this in Cygwin, or CMD.exe; Linux+Mono will work once my patch to the F# compiler is accepted):

mkdir proj
cd proj

Download NuGet.exe command-line somewhere and alias it:

set-alias nuget path\to\nuget.exe

Install latest (pre-release) FAKE from NuGet:

nuget install FAKE -pre
ls

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----          4/3/2013   9:11 PM            FAKE.2.1.173-alpha

Good, we got the latest! Now, alias fake:

set-alias fake FAKE.2.1.173-alpha\tools\FAKE.exe

Now we are ready to test FAKE boot workflow.

fake boot init
Generated conf.fsx and build.fsx
./conf.fsx

The conf.fsx script uses F# to specify the build dependencies of your project and fetch them from NuGet. Edit it, and add a dependency on the latest Microsoft.AspNet.WebApi.SelfHost. Dependencies will be installed transitively:

module FB = Fake.Boot
FB.Prepare {
    FB.Config.Default __SOURCE_DIRECTORY__ with
        NuGetDependencies =
            let ( ! ) x = FB.NuGetDependency.Create x
            [
                 !"Microsoft.AspNet.WebApi.SelfHost"
            ]
}

Save that. We can fetch the dependencies and configure the build:

fake boot conf
ls packages
cat ./build/boot.fsx

You see the NuGet packages have been installed and an F# file with the reference list was generated.

Now let us edit the main `build.fsx` file that is going to execute with the dependencies.

./build.fsx

Normally this would be your build logic, but just because we can, can script a little WebServer:



Now, we can run it:

fake boot
Serving http://localhost:8080
Press Enter to quit.

Where to go from here: check out the various tasks that FAKE can do for you already. If something is missing, write it in F#, create a NuGet package, and publicize your work. Others will be able to get it in their FAKE scripts by simply referencing your package.

I would like to see FAKE be able to do all the chores, including generating and managing Visual Studio and other IDE files, creating and publishing NuGet packages, initializing project/solution templates, upgrading references, generating documentation, generating boilerplate to make your project built "from scratch", anything you can think of. Rule of thumb: there is no good reason to write any logic in MSBuild or XML when you can write F#. It is portable, and makes it easy to avoid repeating yourself. If XML is needed for some tool to read, generate if from F#. I have wasted enough time with MSBuild and am not coming back.

No comments:

Post a Comment