Using Latest NUnit Version With MSpec

As I’ve been working another blog post about my adventures in learning BDD ala MSpec, I ran into something that I wanted to share as the problem wasn’t immediately obvious (to me anyway).

The problem is that MSpec has a dependency on version of the nunit.framework assembly – and frankly, it’s not really a very big problem.  In fact, I didn’t even notice it until now because I had been running all of my specs exclusively through the Resharper runner (enabled by the MSpec plugin).

** As a side note, using R# with the MSpec plugin absolutely rocks, and while the runner is needed for integrating MSpec with your automated builds, I would totally recommend R# for your regular dev rhythm.

In my project, I originally had some integration tests in the same assembly as my specifications.  As a result, I had a direct reference to NUnit (version in addition to the reference to Machine.Specifications and Machine.Specifications.NUnit (which has a reference to version  As a result, the later version of NUnit was being copied to my bin folder and throwing a file load exception for every specification when run using the console runner.


My initial reaction was to simply move all my integration tests to a different assembly and remove the direct NUnit reference in my specifications assembly (remember that referencing Machine.Specifications.NUnit will copy the version of NUnit to the bin folder that MSpec expects.  No problem – everything works as you would expect.

However, it seems reasonable to me that, at least in larger projects that are wanting to incorporate specs and not have to re-write all existing tests, that it would be good to simply reconfigure the MSpec console runner to use the latest version of NUnit.  This can be done easily using the standard .NET assembly binding redirection feature.  Simply create a file named Machine.Specifications.ConsoleRunner.exe.config and drop it into the MSpec folder that contains your console runner (Machine.Specifications.ConsoleRunner.exe).  The contents of the file should look like this.

<?xml version="1.0"?>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <assemblyIdentity name="nunit.framework"
                            culture="neutral" />
          <bindingRedirect oldVersion=""

Run the MSpec console again, and voila! Works like a charm.


About Howard Dierking

I like technology...a lot...
This entry was posted in BDD, MSpec, R#. Bookmark the permalink. Follow any comments here with the RSS feed for this post.