c# - 将 .NET 程序集引用解析为不同的名称?

标签 c# .net asp.net clr-hosting

我的项目引用了 Library1.dllLibrary2.dllLibrary2.dll 依赖于 Library1.dll,但它被编译为以不同的名称 Library1.Net40.dll 引用它。

是否有一种好方法告诉我的应用程序将所有对 Library1.Net40.dll 的引用重定向到解析为 Library1.dll?也许类似于使用 重定向版本的方式?

我有一个处理 AppDomain.AssemblyResolve 事件的解决方案,但它有点乱七八糟,我希望有更好的方法来执行此操作。

编辑: 供任何人引用,以下是我最终使用 AppDomain.AssemblyResolve event 解决它的方法重定向到不同的程序集。

最佳答案

你试过玩<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.

关于c# - 将 .NET 程序集引用解析为不同的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4262602/

相关文章:

c# - 更新数据库 Image 只存储 0x

c# - CS1617 : Invalid option ‘6’ for/langversion; must be ISO-1, ISO-2、3、4、5 或默认

c# - 带 Linq 的 Entity Framework 、内部连接、分组依据、排序依据

c# - 我应该如何在 ASP.NET MVC 中实现 "Forgot your password"?

c# - .NET 探查器如何工作?

.net - C# WMI 中的软盘噪音 - Win32_LogicalDisk 类

c# - 使用 LINQ 从 DataTable 获取不同的项目

c# - 从另一个应用程序更改应用程序的变量

c# - 确保用户 X 不查询用户 Y 的数据

c# - 是否可以通过 COM 互操作转发委托(delegate)?