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

NuGet引用包版本冲突解决指引:ServiceCollection类型重复问题

解决ServiceCollection程序集版本冲突问题
  • 统一所有项目的NuGet包版本
    打开解决方案的NuGet包管理器,找到Microsoft.Extensions.DependencyInjection和Microsoft.Extensions.DependencyInjection.Abstractions这两个包,选中所有关联项目,把它们统一更新到同一个稳定版本(比如直接升到6.0.0版本,优先选更高的兼容版)。如果是手动管理csproj文件,直接把所有项目里这两个包的版本号改成一致的。

  • 清理残留文件并重建
    删除所有项目下的bin和obj文件夹,避免旧版本程序集残留。然后在IDE里执行“清理解决方案”,再重新生成整个解决方案。

  • 添加程序集绑定重定向(可选)
    如果上述操作后仍有冲突,在项目的app.config或web.config里添加绑定重定向配置,强制系统使用指定版本的程序集:

    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="Microsoft.Extensions.DependencyInjection" publicKeyToken="adb9793829ddae60" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>
    

    注意把newVersion替换成你统一使用的版本号。

  • 排查第三方依赖的间接引用
    有些第三方NuGet包可能会间接引用不同版本的这两个程序集。可以通过NuGet包管理器查看每个第三方包的依赖项,要么更新第三方包到兼容你选定版本的最新版,要么换用依赖版本一致的替代包。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 08:21:57