2014-01-26

Code your TFS builds in F# instead of XAML

Last night, I pushed a release build of SourceLink.Fake to the NuGet Gallery. It is an extension for FAKE - F# Make. One main feature is to allow running FAKE build scripts from Team Foundation Build. A build.fsx script has access to the entire TFS API. It is much more fun and productive coding in F# than in XAML. I'm using SourceLink.Fake to build itself. Here is the log for the build:


The "Download drop as zip" link gives you access to the build output.

Installation in a Visual Studio Online Git Project

You must add SourceLink.Tfs.dll and SourceLink.dll to the custom assemblies folder of the build controller. Then add a build definition and set the build process template to be VsoGit.xaml. Those three files may be found in the SourceLink.Fake tools folder. I created a "vsobuild" branch with just those three files. The assemblies must be in a subfolder to work. I named the folder "assembly".

Custom Assemblies

Use Team Explorer in Visual Studio to set the custom assemblies path for the build controller.




In that vstfs path the first "SourceLink" is the Team Project name, the second "SourceLink" is the Git repository name, "vsobuild" is the branch, and "assembly" is the folder that contains the assemblies in the branch.

Set Process Template

Use Team Explorer in Visual Studio to create a new build definition and set the process template to VsoGit.xaml.



FAKE Build Parameters

The "MSBuild arguments" may be used to pass in the default target and build parameters to FAKE, the same as you would call build.cmd or build.sh. In the build.fsx you can use hasBuildParam and getBuildParam functions accordingly. That is the only custom parameter that the TFS web UI supports, which is perfect for FAKE integration. You can set the defaults in the build definition and optionally override them when you queue a build.

Git commands for vsobuild

Here are the git commands I used to create the "vsobuild" branch and upload the three files. This is based on creating a "gh-pages" branch manually, which has some more documentation.

git checkout --orphan vsobuild
git rm -rf .
git add VsoGit.xaml assembly
git commit -a -m "F# Make build template"
git push origin vsobuild