C# 引用同一个dll不同版本的程序集

因为项目需要所以必须在项目中引用不同版本的同一程序集

我要引用的文件是newtonsoft.json.dll 两个版本为12.0.0.0 和4.0.0.0

1.如果已经先引入了newtonsoft.json 12.0.0.0版本的程序集,如果直接引入另一个版本的程序集的话会提示不成功,所以先将另一个版本的程序集改名为newtonsoftv2.json,这样两个程序集都添加到了引用里边。

2.在web.config中配置

csharp 复制代码
<dependentAssembly>
	<assemblyIdentity name="Newtonsoft.Json"  publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
	<codeBase version="4.0.0.0"  href="ref\NewtonsoftV2.Json.dll" />
	<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
	<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"  culture="neutral" />
	<codeBase version="12.0.0.0"   href="Newtonsoft.Json.dll" />
	<bindingRedirect oldVersion="4.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>

2.然后在引用里边改变程序集的别名,如图

3.在引用newtonsoft的类文件中按如下写:

相关推荐
木心爱编程14 小时前
C++程序员速通C#:从Hello World到数据类型
c++·c#
※※冰馨※※14 小时前
【c#】 使用winform如何将一个船的图标(ship.png)添加到资源文件
开发语言·windows·c#
咕白m62515 小时前
C# 实现 Word 与 TXT 文本格式互转
c#·.net
土了个豆子的1 天前
04.事件中心模块
开发语言·前端·visualstudio·单例模式·c#
@areok@1 天前
C++mat传入C#OpencvCSharp的mat
开发语言·c++·opencv·c#
时光追逐者1 天前
C# 哈希查找算法实操
算法·c#·哈希算法
三千道应用题1 天前
C#语言入门详解(18)传值、输出、引用、数组、具名、可选参数、扩展方法
开发语言·c#
micoos1 天前
C#-LinqToObject-Element
c#
忧郁的蛋~1 天前
使用.NET标准库实现多任务并行处理的详细过程
开发语言·c#·.net