我的项目引用了 Library1.dll 和 Library2.dll。 Library2.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/