SSIS脚本任务Newtonsoft.Json版本冲突问题求助
SSIS包Newtonsoft.Json版本冲突问题解决指导
问题描述
我有一个包含C#脚本任务的SSIS包,出现如下警告:已引用Newtonsoft.Json v12,但提示同时存在v13的引用。无法找到v13的引用来源,即使新建项目和脚本任务,该警告仍会出现。脚本在本地可正常运行,但部署到SQL Server 2017服务器后,执行Newtonsoft相关代码时失败。使用Visual Studio 2019。
警告详情
Severity Code Description Project File Line Suppression State Warning Found conflicts between different versions of "Newtonsoft.Json" that could not be resolved. There was a conflict between "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" was chosen because it was primary and "Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" was not. References which depend on "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" [C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Newtonsoft.Json\v4.0_12.0.0.0__30ad4fe6b2a6aeed\Newtonsoft.Json.dll]. C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Newtonsoft.Json\v4.0_12.0.0.0__30ad4fe6b2a6aeed\Newtonsoft.Json.dll Project file item includes which caused reference "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Newtonsoft.Json\v4.0_12.0.0.0__30ad4fe6b2a6aeed\Newtonsoft.Json.dll". Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL References which depend on "Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" []. C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\PublicAssemblies\SSIS\140\Microsoft.SqlServer.ManagedDTS.dll Project file item includes which caused reference "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\PublicAssemblies\SSIS\140\Microsoft.SqlServer.ManagedDTS.dll". Microsoft.SqlServer.ManagedDTS, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 Microsoft.SqlServer.ScriptTask, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 ST_0a72ca207021453086f7f4306b6593b0 C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2203
根源分析
从警告日志可见,冲突源于SSIS核心组件Microsoft.SqlServer.ManagedDTS.dll依赖Newtonsoft.Json v13,而项目直接引用了v12版本。本地运行正常是因为Visual Studio自动处理了版本重定向,但SQL Server 2017服务器缺少该重定向配置,导致执行失败。
解决步骤
1. 添加程序集绑定重定向配置
在SSIS项目的app.config文件中添加重定向规则,强制所有组件使用v12版本:
<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="12.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
若项目无
app.config,右键项目→添加→新建项→选择“应用程序配置文件”创建。
2. 修正脚本任务的NuGet引用
- 打开脚本任务编辑器,进入“脚本”选项卡,点击“编辑脚本”。
- 在脚本项目中,右键“引用”→管理NuGet程序包,卸载现有Newtonsoft.Json,重新安装v12.x版本。
- 确认引用路径指向本地项目的NuGet包,而非GAC中的版本。
3. 部署时同步依赖文件
- 部署到SQL Server 2017时,将Newtonsoft.Json v12的DLL文件复制到服务器SSIS运行目录(通常为
C:\Program Files\Microsoft SQL Server\140\DTS\Binn),或者在脚本任务的引用属性中设置复制本地为True,确保DLL随包部署。
4. 排查GAC和组件冲突
- 若问题持续,检查服务器GAC中是否存在Newtonsoft.Json v13,如有可考虑卸载(操作前需确认无其他应用依赖)。
- 通过上述重定向配置可强制覆盖VS组件的v13依赖,无需修改Visual Studio的核心组件。
内容的提问来源于stack exchange,提问作者keatklein
相关产品推荐
相关产品推荐

