views:

51

answers:

2

Let's assume I have two assemblies:

MyExecutable.dll    version 1.0.0
MyClassLibrary.dll  version 1.0.0

Now, MyExecutable.dll currently uses MyClassLibrary.dll's classes and methods (which include some algorithms). Most of those algorithms were made on the run, being that later I'll want to refine them if needed. This means, I won't change the interface of those classes but the code itself will see some changes.

The question at hand is, MyExecutable.dll will be expecting MyClassLibrary.dll 1.0.0 and I'll want it to use version 1.0.1 (or something like that). I don't want to have to recompile MyExecutable.dll(because actually there might be more than just one executable using MyClassLibrary.dll). Is there a solution for this problem? I've heard about the GAC, but if possible I'd like to stay away from it.

Thanks

+2  A: 

You are looking for Assembly Binding Redirection - this is a configurable way to tell .NET what version assemblies to use.

Oded
Should that be applied to the .exe or the .dll in this case? I mean, to which configuration file?
devoured elysium
The config for whatever uses the redirected assembly - probably the `.exe` config.
Oded
But that means that every time I have to update the library I'll have to go an check all the other assemblies that might be using this library. Wouldn't it be possible to just have a config file on the library itself so that'd be just update the library, the library's config file and that's it?
devoured elysium
@devoured elysium - That's how the system works... And if the different exe files need different versions? The idea is that you configure the exe to know _exactly_ what version it needs. Hopefully the ones that need specific configuration are the exception to the rule, not the norm.
Oded
+1  A: 

The first solution is Assembly Binding redirection, already recommended by Oded.
It is advantageous if you have a smaller .dll and want to make something work with its newer versions.

The second option is creating a separate assembly for the interfaces, and referencing only that from the executable.
This way, you can allow third parties to build stuff against your library without giving them the exact library's assembly. (Eg. they can't decompile it with Reflector, so it is more secure this way.)
As long as the interface assembly doesn't change, you can change other stuff in the library pretty much as you want.

Venemo