在程序中加载依赖项(不同版本的dll)的常见做法 [英] Common practice to load the dependency(different version of dll) in program

查看:39
本文介绍了在程序中加载依赖项(不同版本的dll)的常见做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个代码使用了 2 个第三方 dll.一个是 NLog.Extensions.Logging 版本 1.6.1 用于记录其他是用 .net 标准 2.0 编写的 CryptoProvider.dll .NLog.Extensions.Logging 内部使用 Microsoft.Extensions.Logging 版本 2.1.0CryptoProvider.dll 内部使用Microsoft.Extensions.Logging 版本 2.0.0.所以现在有一个关于版本不匹配的问题.那么我应该如何设计 CryptoProvider dll.以便解决问题.

Suppose there is a code which use 2 third party dll's. one is NLog.Extensions.Logging version 1.6.1 for logging other is lets say CryptoProvider.dll written in .net standard 2.0. NLog.Extensions.Logging internally using Microsoft.Extensions.Logging version 2.1.0 while CryptoProvider.dll internally use Microsoft.Extensions.Logging version 2.0.0. So now there is a issue regarding version mismatch. So how should I design to CryptoProvider dll. so that resolve the issue .

推荐答案

可以使用 app.config 文件重定向程序集绑定assemblyBindingindingRedirect 如下所示

there is a possibility to redirect assembly binding using the app.config file assemblyBindingindingRedirect like below

      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
      </dependentAssembly>

这可以将所有程序集 Newtonsoft.Json 版本引用重定向到 12.0.0.0.如果安装的包有不同的依赖版本,VS 通常会自动添加这些重定向.

This can redirect all assembly Newtonsoft.Json version references to be resolved to 12.0.0.0. Usually VS adds those redirects automatically if installed packages has different dependency versions.

但只有在重定向版本之间没有重大更改时才有效.

But it works only if there are no breaking changes between the redirected version.

不确定在 .net 框架和 .net 核心程序集之间混合是否有效.

Not sure that it will work to mix between .net framewok and .net core assemblies.

.net core 的程序集绑定重定向使用 deps.json

这篇关于在程序中加载依赖项(不同版本的dll)的常见做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆