In my solution, I have several projects which use Log4Net (1.2 and 2.5).
Then I have a project where I do all the unit testing (of the other projects). So I'm in a situation where depending on what I test/mock I would need Log4Net 1.2 or 2.5.
I read you could support different version of a single assembly in an application (using codebase etc.) but is it even possible to support different version of a single assembly into a project? If so, how?
EDIt:
Here's a tiny (2 classes, 2 methods, 2 constructors) project showing my issue:
https://srv-file1.gofile.io/download/EQFdOs/212.76.254.142/Log4NetMulti.zip
(I hope the link work)
Thanks to Pikoh's advices I managed to make it work. But since it requires more than just using alias and rename dll, I'll write down the whole process.
In you code, make use of the aliases, using "extern alias" keywords.
extern alias log4net_1_2_10_0;
using log4net_1_2_10_0.log4net;
using System.Web;
...
Add codebases into your config file. Those should refer to the dll you placed into your folder, with the proper version and token.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" />
<codeBase version="1.2.15.0" href="Libs/log4net.1.2.15.0.dll"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="1b44e1d426115821" />
<codeBase version="1.2.10.0" href="Libs/log4net.1.2.10.0.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
You can reference diferent versions of the same dll using Alias
, as is explained here MSDN:
Add the reference to both the dlls in your client application solution. Then in the Solution Explorer under the reference node select the first (old version) class library. In the property window change Aliases field from global to oldVer. Make similar change after selecting the newer class library as well. You are then good to go…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With