VS Code运行ASP.NET Core 5 Web API报NU1101找不到EntityFrameworkCore包怎么办
NU1101 报错解决方案
报错原因
报错核心是NuGet当前仅启用了Microsoft Visual Studio 离线包源,该源不包含Microsoft.EntityFrameworkCore系列公开依赖包,无法拉取对应资源导致启动失败。
修复步骤
- 第一步:查看当前NuGet源配置
打开终端执行命令:dotnet nuget list source
检查输出列表中是否存在nuget.org官方源,以及状态是否为启用。 - 第二步:配置官方NuGet源
若列表中无官方源,执行添加命令:dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
若官方源存在但状态为禁用,执行启用命令:dotnet nuget enable source nuget.org - 第三步:清理缓存并还原依赖
先清理本地NuGet缓存避免旧缓存干扰:dotnet nuget locals all --clear
进入项目根目录(API.Core.csproj所在目录)执行依赖还原:dotnet restore - 第四步:验证修复效果
还原完成后重新执行启动命令:dotnet run
备选优化方案
如果日常不需要使用Visual Studio离线包源,可以执行命令禁用该源,避免源优先级匹配异常:dotnet nuget disable source "Microsoft Visual Studio Offline Packages"
内容的提问来源于stack exchange,提问作者Olugbenga
相关产品推荐
相关产品推荐

