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

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

概述我的项目引用了Library1.dll和Library2.dll. Library2.dll依赖于Library1.dll,但它被编译为以不同的名称Library1.Net40.dll引用它. 是否有一种很好的方式告诉我的应用程序重定向Library1.Net40.dll的所有引用以解析为Library1.dll?也许类似于使用< bindingRedirect>?重定向版本的方式 我有一个处理A 我的项目引用了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.dllLOG: Entering download cache setup phase.LOG: Assembly name is: library1,Version=3.5.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeedWRN: Comparing the assembly name resulted in the mismatch: nameERR: 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程序集引用解析为其他名称?全部内容,希望文章能够帮你解决c# – 将.NET程序集引用解析为其他名称?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1243477.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存