Programming October 20, 2011

Extending Phantom

I’ve been using Phantom, a .NET build system written for writing build scripts in C# and Boo by Jeremy Skinner, in various projects for quite a while and been very happy with it. I’ve even been so happy that I’ve never had any need to extend it. Until now.

While there is some documentation in the wiki about how create custom functions it did take a little while for me to figure out, mostly due to my inexperience with Boo. To create an extension what we have to do is to create a new class library project and reference Phantom.Core. We then create a class that implements the IRunnable<T> interface, like this:

using System;
using Phantom.Core.Language;

namespace Funky.PhantomExtensions
    public class doStuff : IRunnable<doStuff>
        public string message = "Hello there";

        public doStuff Run()
            return this;

        public void SayBye()
            Console.WriteLine("Bye bye");

After compiling we place the compiled assembly in the same folder as the Phantom assemblies and import it in our build script. We’re then good to go and can use it, like this:

import Funky.PhantomExtensions

target default:
  doStuff() //will print "Hello there"

  doStuff(message: "Hola senor") //will print "Hola senor"
  with doStuff(): //will print "Bye bye" and "Howdy"
    message = "Howdy"

PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.

Joel Abrahamsson

Joel Abrahamsson

I'm a passionate web developer and systems architect living in Stockholm, Sweden. I work as CTO for a large media site and enjoy developing with all technologies, especially .NET, Node.js, and ElasticSearch. Read more


comments powered by Disqus

More about Programming