You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何排查.NET Core 2.1解决方案中导致构建失败的SDK依赖来源?

.NET Core 2.1 构建时 System.Runtime.CompilerServices.Unsafe 版本冲突问题解决

问题场景

  • 维护未升级的.NET Core 2.1代码库,引入NuGet包FFMpegCore后,其依赖System.Text.Json 7.0.1
  • 本地VS2017可正常构建,但构建服务器执行dotnet build时,出现System.Runtime.CompilerServices.Unsafe与netcoreapp2.1不兼容的错误

排查过程

  1. 先将FFMpegCore降级至依赖System.Text.Json 6.0.1的版本,仍不支持.NET Core 2.1
  2. 再降级至依赖System.Text.Json 5.0.1的版本,该版本依赖的System.Runtime.CompilerServices.Unsafe 5.0.0看似兼容,但构建服务器仍报错:

/home/build/.nuget/packages/system.runtime.compilerservices.unsafe/6.0.0/buildTransitive/netcoreapp2.0/System.Runtime.CompilerServices.Unsafe.targets(4,5): error : System.Runtime.CompilerServices.Unsafe doesn't support netcoreapp2.1. Consider updating your TargetFramework to netcoreapp3.1 or later. [/opt/build/develop/site/site.csproj]

  1. 本地Visual Studio显示FFMpegCore仅通过System.Text.Json依赖Unsafe 5.0.0,但构建服务器存在不兼容版本残留
  2. 尝试切换至依赖Newtonsoft.Json的旧版FFMpegCore,甚至切换到无FFMpegCore的分支,构建仍报错

解决方法

执行NuGet缓存清理命令:

dotnet nuget locals all --clear

清理完成后,构建服务器执行dotnet build恢复正常

结论

.NET Core 2.1环境下不应引入System.Runtime.CompilerServices.Unsafe包,若出现版本冲突残留问题,清理NuGet本地缓存是有效的解决手段

内容的提问来源于stack exchange,提问作者jlmt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 06:25:01