Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Two Different Versions of the Same Library

Tags:

c#

.net

ilmerge

I am developing a small library that will be used across multiple applications. I would like to use some third-party libraries within my own library (e.g. log4Net, Entity Framework, etc.). I would imagine I can either deploy the DLLs alongside my own library, or use ILMerge to create a single DLL (I know little about ILMerge having never tried it).

I'm concerned about what will happen if the applications that consume my library also use the same third party libraries that I will be using. For example, if I use log4Net version 1.2, and a consuming app uses log4Net version 1.0, will I get a conflict of some sort, or will only one version of the assembly not load?

Does ILMerge prevent this? How is this typically resolved when developing a library with 3rd party dependencies?

like image 435
Phil Sandler Avatar asked Oct 22 '22 08:10

Phil Sandler


1 Answers

You may use the extern alias:

You might have to reference two versions of assemblies that have the same fully-qualified type names. For example, you might have to use two or more versions of an assembly in the same application. By using an external assembly alias, the namespaces from each assembly can be wrapped inside root-level namespaces named by the alias, which enables them to be used in the same file.

Here's a Extern alias walkthrough.

like image 53
Alex Filipovici Avatar answered Nov 15 '22 04:11

Alex Filipovici