Creating a new gemspec for the Nubular Project (Nu) is easier than you might think

I just started using Nu to manage the dependencies in my Fluency project. I had used package managers for ruby and php in the past, and loved them, so I couldn’t pass up the opportunity to try out Nu. I am glad I did.

What the heck is Nu?

Nu is a package manager for .NET (finally!). It allows you to install code libraries and all their dependencies automatically, and keep them updated. If you have ever heard of RubyGems, this is the same thing. In fact, its built on top of ruby gems!

Installing Nu

To use Nu, you first need to install ruby. You can get it here. Then upgrade RubyGems by dropping to a command prompt and typing

gem update --system

Then to install Nu you type

gem install nu

And that’s it…Nu is installed and ready to go.

Using Nu

Using Nu is dirt simple. Wanna install NUnit?

C:\project>nu install nunit
Gem nunit is not installed locally - I am now going to try and install it
Successfully installed nunit-
Installed package nunit.

Done! How about NHibernate?

C:\project>nu install nhibernate
Gem nhibernate is not installed locally - I am now going to try and install it
Successfully installed nhibernate-
Loading dependency: castle.core =
Loading dependency: castle.dynamicproxy2 =
Loading dependency: castle.core =
Loading dependency: log4net =
Installed package nhibernate.

Sure beats the pants off navigating out to the website to download the latest version, doesn’t it? And it even installed all the dependencies.


Creating a gem to be installed using Nu

So what does it take to make a project installable using Nu? Not much. I was surprised at how easy it was.

When I converted Fluency to install all its dependencies using Nu, I found one library that that wasn’t yet packaged as a gem and installable through Nu. This was the SharpTestsEx library. So I did what any self-respecting supporter of open-source software would do, I decided to add it myself so anyone else could use it.

1. Prepare the gemspec

To do this, I created a gems folder and in it, a gemspec file “sharptestsex.gemspec” with the following contents

version ="../VERSION",__FILE__)).strip do |spec|
  spec.platform    = Gem::Platform::RUBY        = 'sharptestsex'
  spec.version     = version
  spec.files = Dir['lib/**/*']
  spec.summary     = 'Sharp Tests Ex - .NET Fluent Assertions for Your Tests'
  spec.description = '#TestsEx (Sharp Tests Extensions) is a set of extensible extensions. The main target is write short assertions where the Visual Studio IDE intellisense is your guide. #TestsEx can be used with NUnit, MsTests, xUnit, MbUnit.'
  spec.authors           = ['Fabio Maulo','JDiamond']             = ''
  spec.homepage          = ''
  spec.rubyforge_project = 'sharptestsex'

and a “VERSION” file that simply contained the version number

I then created a gems/lib/ folder and placed the binaries in it. The spec.files attribute indicates that I want to include all the files in this folder in the gem.

2. Build and test the gem locally.

Then I built the gem at the command prompt with

gem build sharptestsex.gemspec

This will product the gem file names sharptestsex- I tested it with nu locally by installing the gem directly (without going to the rubygems server) by specifying the filename of the gem.

gem install sharptestsex-

This installed it from my local drive into the gem cache. The gem cache is where nu gets the libraries. If nu does not find the requested library in the gemcache, it asks rubygems to get it from the server. Installing it like I did above ensured its in the cache so nu could find it. Then I tested that nu could install it.

nu install sharptestsex

Once I saw it all worked, I uninstalled the gem so that I would be able to test that it pulls from the server. Uninstalling the gem deletes it from the local gemcache. I had to do this because if it existed in the cache, it wouldn’t even try to download if from the server the next time I test it. I uninstalled it with…

gem uninstall sharptestsex

3. Push the gem to

Now I was ready to push the gem out to To do that, I needed to sign up for a free account, which was quick and painless. The I pushed the gem up.

gem push sharptestsex-

I was prompted for my login and password, and then the gem was uploaded. 

4. The final test

Then my new gem is ready to install with nu! I tested it with…

nu install sharptestsex

I checked, and sure enough, I saw a lib folder that contains a sharptestsex folder with all the binaries. It was way easier than I thought.


I drew heavily from the following resources while getting this to work.

This entry was posted in .NET, C# and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>