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的类文件中按如下写:

相关推荐
北京理工大学软件工程5 小时前
C#111
开发语言·c#
雪飞鸿11 小时前
ArrayPoolWrapper简洁、安全的ArrayPool
c#·.net·.net core·原创
海盗123412 小时前
C#上位机开发-S7协议通信
开发语言·c#
FeBaby12 小时前
ReentrantLock 与 synchronized 底层实现对比图解
开发语言·c#
烟话614 小时前
C# 内存机制详解:值类型、引用类型与 String 的不可变性
java·jvm·c#
我是唐青枫14 小时前
C#.NET MemoryMarshal 深入解析:零拷贝内存重解释、二进制读写与使用边界
c#·.net
susan花雨15 小时前
C#异步并行处理的用法
c#
weixin_5206498715 小时前
Winform创建与启动
开发语言·c#
武藤一雄15 小时前
WPF中逻辑树(Logical Tree)与可视化树(Visual Tree)到底是什么
microsoft·c#·.net·wpf·.netcore