C# Referencing two different versions of same asse

2019-08-29 11:40发布

问题:

I need to reference two versions of the same library (Coherence .NET) in my library project and use them both so I've renamed the dll's and referenced them in my project via aliases, however when I try to compile my library I get this warning

warning MSB3243: No way to resolve conflict between "Coherence, Version=12.1.2.0, Culture=neutral, PublicKeyToken=0ada89708fdf1f9a" and "Coherence, Version=3.3.0.2, Culture=neutral, PublicKeyToken=0ada89708fdf1f9a". Choosing "Coherence, Version=12.1.2.0, Culture=neutral, PublicKeyToken=0ada89708fdf1f9a" arbitrarily

And when I try to register my library (it needs to be registered using RegAsm.exe) I get this erorr

error MSB3217: Cannot register assembly "C:\Program Files\******.dll". Could not load file or assembly 'Coherence, Version=3.3.0.2, Culture=neutral, PublicKeyToken=0ada89708fdf1f9a' or one of its dependencies. The system cannot find the file specified

Two assembly dll's that I've referenced are Coherence.v3.3.dll and Coherence.v12.1.dll

I've tried adding this to my library's App.config but it didn't solved the problem as I'm still getting same error

  <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Coherence" publicKeyToken="0ada89708fdf1f9a" culture="neutral" />
    <codeBase version="3.3.0.2" href="Coherence.v3.3.dll"/>
    <codeBase version="12.1.2.0" href="Coherence.v12.1.dll"/>
  </dependentAssembly>
</assemblyBinding>
 </runtime>

回答1:

As variant, you can create 2 "proxy" assemblies, for each library version.



回答2:

Edit the project file .csproj and make sure HintPath is present and SpecificVersion=True.

<Reference Include="Coherence, Version=12.1.2.0, ...">
  <HintPath>..\references\******.dll</HintPath>
  <SpecificVersion>True</SpecificVersion>
</Reference>

After that you save the file and again rebuild it.



标签: c# .net dll