Merging DLLs and changing control namespaces

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

To complement, sake lets you say that the third-party dll is nLog. How can I consider cases where the consumer of the federated dll already has NLog as a reference in its project?

Ideally, what I would like to do is change the NLog namespace in my project to "XyzNLog", which means that the user does not need to do any aliases ... Any idea how I can do this?

Now I know that I can add aliases to my NLog project, so I have to refer to it as XyzNLog, but I want the same to be passed to the consumers of the unified DLL so that there will never be a conflict.

UPDATE - Solution

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

Bingo! Thus, using ILMerge, it becomes possible to combine third-party DLLs with the providers of our own DLLs, that is, we will only have one DLL for deployment. But that’s not all, we can go one step further and tell ILMerge how to internalize all the Dependencies . What it does converts all third-party classes to be declared as internal, which means they can only be used from within the final DLL. Woah! problem solved =)

Given this problem, when the consumer of my dll could also have an NLog, quit ... because my reference NLog switches to everything internal! This is exactly what I want.

Does anyone have any feedback or thoughts on this?

+6
source share
2 answers

I agree with Hans, I would highly recommend exempting him from registering the DLL separately.

Otherwise, you may end up in a hellish DLL that removes your consumers.

You can then develop some smart deployment methods to determine if DLLs are registered, etc.

+1
source

I have to agree with @Hans Passant (and here is some information about the frequently discussed DLL addon), but since you asked a question, I will try to answer it.

You can link a third-party DLL as a resource. Please see this question for details.

For other questions, I simply expose the appropriate classes from a third-party DLL in my own namespace, and perhaps use extension methods to provide any additional functions you want.

For example, you can grant access to the NLog Log() method using a static method in your class, say XyzNLog.Logger.Log() , taking care of initialization and anything internally, inside your code (static constructor or whatever something else that you like up). Since you download the NLog assembly using the method above, you will be the only one who has access to the built-in NLog assembly directly, and the user will not be able to access it. Now you are not taking advantage of the fact that all classes are automatically opened from NLog, but in this case you still have to set them manually.

EDIT . Another approach is to try using ILMerge with the / internalize flag as described here . You may not be able to completely solve the problem, but look in this article to find out if you can avoid the errors described by the author. Spoiler warning: this is not all peaches on this, but it can work with enough effort.

0
source

Source: https://habr.com/ru/post/887085/


All Articles