How To – Gems And .NET – Dependencies (References)

In my last post I didn’t mention dependencies.  Dependencies are their own animal. They require a couple more things to be in place. Let’s talk about those things.

In the .NET world, the dependency for compiled bits is usually an exact version of a reference.

Let me explain. So for example, you have a reference to log4net, and you don’t ILMerge it into your assembly. You now have a dependency that the DLL needs to be there and a particular version (outside of redirecting the bindings).  So what I’m getting at is that you require an exact version of a particular DLL. And what you really need is an exact name, version, culture, and public key token of a DLL.  But let’s keep things simple. It’s really the version and the name when culture is neutral (and the key shouldn’t change in the same version). So just the name and version.

Adding a Reference as a Dependency

For each reference you have to a library, you find out what version it is (assembly version) and then add that as a dependency. You can do that by cracking open reflector and taking a look at the actual assembly version.

The assembly version

Don’t use the properties. Neither file version or product version are going to be accurate here:

 Properties of log4net.dll - file and product verions

There is nothing out there that says that assembly, file and informational (also known as product) versions have to be the same. .NET relies on the assembly version for referencing. It makes sense that we should as well. Here’s a better example where things are different:

Castle File Version Castle Assembly Version

So what would I put in my gemspec? If your reference was to log4net version, then you need to assign a dependency to that exact version. Done like so:


I believe you add each referenced dependency to it’s own line.

Gem Exists?

Now to the sanity check. Before you even add it as a dependency, you want to ensure that the gem exists.

Go to and in the top right there is a search box. Search for your reference there.

Search box on

So let’s search for log4net to be sure it’s there.

Search results for log4net

Sweet! I can move on to my next reference because the right version of the gem exists.

Keep in mind that the name of the gem may not be the one you are looking for and/or the name may be slightly different. For example. I have a gem for UppercuT. The gem is named uppercutbuild because there was already a gem named uppercut.

Gem Doesn’t Exist?

Now if it’s not there, you can add it. When the actual authors want to start managing the gem, you can just add them as owners so they can push their own gems.

To check the owners of a gem you type:

gem owner gemname

Gem owners for log4net

To add someone, according to the gem docs, you issue this command (all on one line):

gem owner gemname --add

And that’s it.

You see how I am listed as the owner of the log4net gems? I am not really the developer, when I created the gem, I tied it as closely as I could to the apache project and the committers. When those guys are ready to own the gem, I have the specs for both 1.2.9 and 1.2.10 (both are commonly referred to without the last version octet) and I can just add them as owners.


Related Posts

Before you comment about “cluttering” the ruby community, please be sure to read this (we’re with you on this):

Gems - Package Management for .NET & How To – Gems & .NET

Walkthrough - Create Gems Even Easier With a Conventional Build (UppercuT)!

The Future is Now!

Posted 07-17-2010 8:04 AM by Rob Reynolds



Rob Reynolds - The Fervent Coder wrote Gems - Package Management For .NET
on 07-19-2010 10:15 PM

The Ruby community has enjoyed a great user experience with a package management system they use called

Rob Reynolds - The Fervent Coder wrote The Future of .NET Open Source Software Delivery
on 07-26-2010 4:21 PM

Imagine we are awhile into the future. How do you get open source releases down to your project so that

Rob Reynolds - The Fervent Coder wrote The Future of .NET Open Source Software Delivery
on 07-26-2010 4:27 PM

Imagine we are awhile into the future. How do you get open source releases down to your project so that

Chris Edwards wrote re: How To – Gems And .NET – Dependencies (References)
on 09-11-2010 12:11 AM

What do you suggest if the dependencies are optional? For instance, I am trying to add SharpTestsEx ( which has 2 ways to use it. One is using the framework independent dll. the other is to use the framework specific dll (sharptestsex.nunit.dll) which has a dependency on nunit.

The problem is that there are multiple optional frameworks you can use. What I don't want is to have all the unit testing frameworks installed when this one is SharpTestsEx is installed. Should I just put the framework dlls in the gem?


Rob Reynolds wrote re: How To – Gems And .NET – Dependencies (References)
on 09-14-2010 5:15 PM

@Chris - it looks like your question was answered on the list. :D

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)