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

运行ASP.NET练习遇多个NU1100异常,求解决方法

问题原因与解决建议

问题核心原因

NU1100错误本质是NuGet无法定位到指定版本的依赖包,结合你的情况,可能的诱因包括:

  • NuGet包源配置异常(默认nuget.org源被禁用或网络无法访问)
  • 本地NuGet缓存损坏,导致已下载的包无法正常读取
  • 项目中Swashbuckle系列包版本不一致(6.2.3和6.5.0),引发兼容冲突
  • .NET 7 SDK安装不完整,缺少对应框架的支持组件

分步解决建议

1. 检查并修复NuGet包源

打开命令行执行以下命令,查看当前包源状态:

dotnet nuget list source
  • 如果没有nuget.org源,执行添加命令:
    dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
    
  • 如果nuget.org源已存在但状态为禁用,执行启用命令:
    dotnet nuget enable source nuget.org
    

2. 清理本地NuGet缓存

执行命令清除所有NuGet本地缓存:

dotnet nuget locals all --clear

之后回到项目目录,重新还原依赖:

dotnet restore

3. 统一Swashbuckle包版本

你的项目中Swashbuckle.AspNetCore和Swashbuckle.AspNetCore.Annotations版本不匹配,修改FruitAPI.csproj文件,将两个包的版本统一为同一兼容版本(比如都用6.5.0):

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="7.0.9" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
    <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
  </ItemGroup>

</Project>

修改完成后再次执行dotnet restore。

4. 验证.NET 7 SDK完整性

执行命令查看已安装的SDK列表:

dotnet --list-sdks

确认输出中包含7.0.x版本的SDK。如果没有,重新下载安装.NET 7.0 SDK,安装完成后重启命令行再尝试还原。

5. 尝试浮动版本匹配(可选)

如果指定版本仍无法找到,可以将版本号改为浮动格式,让NuGet自动匹配兼容的最新版本:

<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="7.0.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.*" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.*" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.*" />

之后执行dotnet restore即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 00:32:42