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. @tim_abell The gigantic ones are for customers who specifically ask for them only :) 1 months ago
  2. Looking to buy a gigantic easter egg filled with candy for delivery in Stockholm. Any recommendations? 1 months ago
  3. @strandberg_m Du måste skriva om resultatet efteråt! 1 months ago
follow me

Latest comments

  1. Joel Abrahamsson wrote "Hi Jonas! The fluent API is really geared towards working..." on Building a search page for an EPiServer site using Truffler
  2. Jonas wrote "Thank you for one more great write up! If you're not lucky ..." on Building a search page for an EPiServer site using Truffler
  3. David Knipe wrote "The CategoriesFacet method will save me a load of headaches ..." on Cool new features in the Truffler .NET API

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