代码之家  ›  专栏  ›  技术社区  ›  Chris Fulstow

正在将.NET程序集引用解析为其他名称?

  •  7
  • Chris Fulstow  · 技术社区  · 14 年前

    我的项目引用 库1.dll 库2.dll . 库2.dll 依赖于 库1.dll ,但它被编译为用另一个名称引用它, 库1.Net40.dll .

    有什么好方法告诉我的应用程序重定向 库1.Net40.dll 决心 库1.dll ? 也许类似于使用“绑定重定向”重定向版本的方法;?

    我有一个解决方案 AppDomain.AssemblyResolve 事件,但这是一个有点黑客,我希望有更好的方法来做到这一点。

    编辑: 对于任何人的参考,下面是我如何使用 AppDomain.AssemblyResolve event 重定向到其他程序集。

    1 回复  |  直到 14 年前
        1
  •  4
  •   Chris Fulstow    14 年前

    你试过玩 <codeBase> element ?

    <configuration>
       <runtime>
          <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
             <dependentAssembly>
                <assemblyIdentity name="Library1.Net40"
                                  publicKeyToken="..."
                                  culture="neutral" />
                <codeBase version="2.0.0.0"
                          href="Library1.dll"/>
             </dependentAssembly>
          </assemblyBinding>
       </runtime>
    </configuration>
    

    (未经测试;不知道是否有效。)

    CF:我把这个更新放在这里,因为评论有点长:)

    好主意,谢谢。我让重定向工作,但它抱怨,因为名称不同,这是日志:

    LOG: Attempting download of new URL file:///C:/Project/bin/Library1.dll.
    LOG: Assembly download was successful. Attempting setup of file: C:\Project\bin\Library1.dll
    LOG: Entering download cache setup phase.
    LOG: Assembly Name is: Library1, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
    WRN: Comparing the assembly name resulted in the mismatch: NAME
    ERR: The assembly reference did not match the assembly definition found.
    ERR: Setup failed with hr = 0x80131040.
    ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.