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()
        {
            Console.WriteLine(message);
            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"
    .SayBye()

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.

Follow me on Twitter

  1. I don't know what she was selling. How rude of me not to ask! 23 hours ago
  2. Muahaha, I just talked a telephone sales person into letting ME send THEM an invoice. She even gave me their org nbr and other details. 23 hours ago
  3. SL/MTR når nya höjder inom dålig informationsspridning idag. Tavlan säger en sak, megafonen en annan, personalen som skriker en tredje 2 days ago
follow me

Latest comments

  1. Martin S. wrote "Perfect stuff, that's just how to do it! Reminds me of an..." on Dear telephone sales woman
  2. Marcus Granström wrote "Poor girl. She didn't know what hit her when she called the ..." on Dear telephone sales woman
  3. Marthin wrote "Happy coding mate!" on New computer, anguish and excitement

About this site

This blog is built with EPiServer Community, EPiServer CMS, ASP.NET MVC and a bunch of other great products. The source code is available for download at the projects page, where you also can read more about this site and my other projects.

read more