Who we are

We are the developers of Plastic SCM, a full version control stack (not a Git variant). We work on the strongest branching and merging you can find, and a core that doesn't cringe with huge binaries and repos. We also develop the GUIs, mergetools and everything needed to give you the full version control stack.

If you want to give it a try, download it from here.

We also code SemanticMerge, and the gmaster Git client.

C# Evaluator

Thursday, November 06, 2008 Pablo Santos , 5 Comments

A month ago or so one of the most exciting new feaures of the upcoming Mono 2.2 was introduced: the C# Evaluator. (Although now, with the new Mono.SIMD, static compilation and so on, I'm not sure which one is the most exciting piece anymore?)

Since then I wanted to blog about it to share my thoughts about the possibilities of this new piece of software. For the folks being around for a while C# Evaluator probably reminded them the old Windows Scripting Host which allowed us programmers to embed powerful scripting in our applications. Now, having C# as a scripting language for your own customization purposes opens new paths for innovation and great ideas.

I'm really eager to include some powerful C# scripting inside Plastic , probably in order to create more powerful workspace selector rules or something like that.

But first I'll try to tell a little bit about how to play with the C# eval in order to learn how it works. First thing is to build and set up the latest mono, so let's start there.

Setting up a 2.2 environment

Once Mono 2.0 was releases I set up a OpenSuse 11 box to play around with it. I was having some trouble building 2.0 on Solaris and OpenSolaris, so having the chance to download and build on Linux was a real pleasure.

So, first I installed OpenSuse 11 with the development tools that can be configured during the installation process. Then I set up 2.0 downloading it from the official Mono repository (check the mono website and go to downloads).

And then I just downloaded trunk from the mono repos

$ svn co svn://anonsvn.mono-project.com/source/trunk/mono
$ svn co svn://anonsvn.mono-project.com/source/trunk/mcs
$ svn co svn://anonsvn.mono-project.com/source/trunk/libgdiplus

And launch the build process

$ autogen.sh --prefix=/home/pablo/monobin
$ make
$ make install

Note I generated the binaries on my home dir.

I built everything under /home/pablo/monobin because I still wanted to use official mono 2.0 for regular operations and 2.2 just for testing and development purposes.

In order to use the newly compiled mono 2.2 you just have to set up your MONO_PATH env var:

$ export MONO_PATH=/home/pablo/monobin
$ export PATH=/home/pablo/monobin/bin/:$PATH

Enter the C# Evaluator
Miguel introduced a sample in his blog post (http://tirania.org/blog/archive/2008/Sep-10.html) but he didn't tell how to perform an action I consider very interesting: making the script interact with your own classes. (Of course I bet he didn't do that because it is more than obvious for most of the people out there, but I hope you still find this sample interesting).

So, as I said, the real beauty of introducing some scripting in your application is not running simple calculations, but making the script interact with your own internal classes or ad-hoc APIs, right?

So, here you can find some very simple source code (the simplest) showing you how to interact with your own assembly. Note I'm adding the current assembly to the script references, and also introducing a using sentence.

using Mono.CSharp;
using System.Reflection;
using System;

namespace CSharpEvalTest
public class Test
public static int val = 1000;

static void Main(string [] args)
"using System; using CSharpEvalTest;");


Evaluator.Run("Test.val = 120;");
Console.WriteLine("val is {0}", val);

How to build the code?


$ gmcs test.cs -r:gmcs.exe

And you're done.

Remember I've modified both PATH (to get the new gmcs) and MONO_PATH!
Pablo Santos
I'm the CTO and Founder at Códice.
I've been leading Plastic SCM since 2005. My passion is helping teams work better through version control.
I had the opportunity to see teams from many different industries at work while I helped them improving their version control practices.
I really enjoy teaching (I've been a University professor for 6+ years) and sharing my experience in talks and articles.
And I love simple code. You can reach me at @psluaces.


  1. Nice post, but you should really be pointing people at our recommended instructions for setting up a parallel mono environment:


    They cover a few more corners.

  2. What autogen are you using? If I follow the official howto there's little info and only a non-working URL. I've installed autogen 5.9.5 through my package manager but when I try to do as you write I get "autogen: illegal option -- prefix=/home/casper/monobin"

  3. Hi Casper,

    It's the autogen.sh which comes with the Mono sources, right? Maybe I typed it wrong, but I don't think so...

  4. Hi Pablo. Yes it is, but autoconf itself doesn't come with mono?! I was just wondering what distro you are on. Because even if I install autoconf in Ubuntu through apt-get, autogen.sh complains with "**Error**: You must have `autoconf' installed to compile Mono."

    I had some trouble building from source in the past, but saw your nice howto and thought I'd give it a try again.

  5. Any ideas for this error?
    {interactive}(1,22): error CS0246: The type or namespace name `CSharpEvalTest' could not be found. Are you missing a using directive or an assembly reference?
    {interactive}(1,2): error CS0103: The name `Test' does not exist in the current context