Igor Kulman

Building Windows Phone apps with FAKE

· Igor Kulman

FAKE is a build automation system with capabilities which are similar to make and rake. It is using an easy domain-specific language (DSL) so that you can start using it without learning F#. If you need more than the default functionality you can either write F# or simply reference .NET assemblies.

I have been using FAKE for quite some time now on some fairly complex projects for not only building but also running tests and creating and pushing Nuget packages and I really like. I decided to add FAKE build scripts to my Windows Phone apps to make the process of generating a XAP file for the Windows Phone Store easier.

The FAKE script I use can by used with any Windows Phone app, it will build all the projects and copy the XAP file to a release directory.

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

// Properties
let buildDir = @".\build\"
let packagesDir = @".\packages"
let releaseDir = @".\release"

// Targets
Target "Clean" (fun _ ->
    CleanDirs [buildDir; releaseDir]

Target "Build" (fun _ ->
    !! @"**/*.csproj"
      |> MSBuildRelease buildDir "Build"
      |> Log "AppBuild-Output: "

Target "Deploy" (fun _ ->
    !! (buildDir + "*.xap")         
        |> Copy releaseDir

Target "Default" (fun _ ->
    trace "Build completed"

// Dependencies
  ==> "Build"  
  ==> "Deploy"
  ==> "Default" 
// start build
Run "Default"

To get the script started, you need a batch file

@echo off
"tools\nuget\nuget.exe" "install" "FAKE" "-OutputDirectory" "tools" "-ExcludeVersion"
"tools\FAKE\tools\Fake.exe" build.fsx

and Nuget.exe in tools\NuGet directory.

See also