Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging DLL's and changing managing namespaces

Tags:

c#

.net

dll

ilmerge

I want to create a single dll that is merged with a 3rd party dll. This means end consumers will only have to deal with 1 dll instead of 2.

For augments sake lets say that the 3rd party dll is nLog. How do I deal with cases where the consumer of the merged dll already has NLog as a reference in their project?

Ideally what I would like to be able to do is change NLog namespace within my project to "XyzNLog", meaning that the user wouldn't need to do any aliasing... Any idea how I might do this?

Now I know I can add aliases to my project for NLog so that I have to refer to it as XyzNLog, but I want the same to carry over to consumers of the merged dll so that there is never a conflict.

UPDATE - Solution

http://blog.mattbrailsford.com/2010/12/10/avoiding-dependency-conflicts-using-ilmerge/

Bingo! So by using ILMerge, it becomes possible to merge the third-party libraries DLLs in with the Providers own DLL, meaning we will only have one DLL to deploy. But that’s not all, we can actually go one step further, and tell ILMerge to internalize all dependencies. What this does it converts all the third party classes to be declared as internal, meaning they can only be used from within the final DLL. Woo hoo! problem solved =)

Given this the problem where the consumer of my dll could also have NLog goes away... as my referenced NLog shifts to being all internal! This is exactly what I want.

Does anyone have any feedback or thoughts on this?

like image 795
vdh_ant Avatar asked May 02 '11 02:05

vdh_ant


1 Answers

I agree with Hans, I would strongly suggest releasing with registering the DLLs separately.

Otherwise, you could be in DLL hell which would drive your consumers away.

You could then devise some clever deploy methods to detect if the DLL is already registered, etc.

like image 59
Mark Kadlec Avatar answered Oct 21 '22 03:10

Mark Kadlec