【问题标题】:C# Referencing two different versions of same assemblyC# 引用同一程序集的两个不同版本
【发布时间】:2014-06-16 10:10:54
【问题描述】:

我需要在我的库项目中引用同一个库 (Coherence .NET) 的两个版本并同时使用它们,因此我重命名了 dll 并通过别名在我的项目中引用了它们,但是当我尝试编译我的库时我收到此警告

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 注册)我得到这个错误

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

我已经尝试将它添加到我的库的 App.config 中,但它并没有解决问题,因为我仍然遇到同样的错误

  <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>

【问题讨论】:

标签: c# .net dll


【解决方案1】:

作为变体,您可以为每个库版本创建 2 个“代理”程序集。

【讨论】:

    【解决方案2】:

    编辑项目文件.csproj 并确保HintPath 存在且SpecificVersion=True

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

    之后,您保存文件并再次重建它。

    【讨论】:

    • 当我这样做时,它会显示警告 MSB3245:无法解析此引用。找不到程序集“Coherence.v12.1,Version=12.1.2.0,Culture=neutral,PublicKeyToken=0ada89708fdf1f9a,processorArchitecture=MSIL”。
    • 对于警告MSB3245,你可以试试C.Evenhuis在这个问题stackoverflow.com/questions/14261412/…的回答
    • 他的建议并没有改变这样一个事实,即当我更改为特定版本 = true 时,我在 Coherence 引用旁边看到黄色图标,它仍然说它无法解决依赖关系
    猜你喜欢
    • 2012-08-30
    • 2010-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    相关资源
    最近更新 更多