C#引用同一程序集的两个不同版本 [英] C# Referencing two different versions of same assembly
问题描述
我需要在我的库项目中引用同一个库(Coherence .NET)的两个版本,并同时使用它们,因此我已经重命名了dll并通过别名在我的项目中引用了它们,但是当我尝试编译我的库时我收到此警告
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
当我尝试注册我的库时(需要使用RegAsm.exe注册),我得到了这个错误提示
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
我引用的两个程序集dll是Coherence.v3.3.dll和Coherence.v12.1.dll
Two assembly dll's that I've referenced are Coherence.v3.3.dll and Coherence.v12.1.dll
我尝试将其添加到库的App.config中,但由于仍然出现相同的错误,因此无法解决问题
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>
推荐答案
编辑项目文件 .csproj
,并确保存在 HintPath
且 SpecificVersion = True
.
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#引用同一程序集的两个不同版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!