微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 将.NET程序集引用解析为其他名称?

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

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

我有一个处理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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐