NuGet包操作及dotnet publish执行异常耗时求助
解决MS NU1100错误及dotnet publish卡顿问题
核心问题根源
- MS NU1100是NuGet找不到匹配的包版本,大概率是你误把本地源和nuget.org的源配置搞混了,导致依赖解析冲突。
- 删除
%AppData%\NuGet\NuGet.Config后,dotnet会默认去连官方源,但如果源配置缺失或网络状况差,会反复重试连接,导致publish卡死。
分步解决方法
1. 修正NuGet源配置
- 打开命令行,执行
dotnet nuget list source查看所有已配置的源,找出错误的本地源(比如把本地源命名成nuget.org或者地址写错)。 - 删除错误源:
dotnet nuget remove source "错误源的名称" - 添加正确的官方源:
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org - 如果需要用本地包,单独加本地源:
dotnet nuget add source "你的.nupkg所在文件夹路径" -n LocalPackages
2. 解决MS NU1100错误
- 打开项目的
*.csproj文件,检查所有<PackageReference>的版本号,确认没有引用不存在的包版本。 - 清理本地NuGet缓存:
dotnet nuget locals all --clear,避免缓存损坏导致解析失败。 - 先执行
dotnet restore,确认依赖恢复成功后再跑publish。
3. 修复publish卡顿问题
- 别直接删NuGet.Config,手动恢复默认配置:在
%AppData%\NuGet\下新建NuGet.Config,写入以下内容:<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> </packageSources> </configuration> - 已经restore成功的话,publish时加
--no-restore参数跳过restore步骤:dotnet publish --no-restore
补充:本地包发布到nuget.org的正确操作
你之前的方法错了,本地.nupkg要传到nuget.org,得用nuget push命令(先装NuGet CLI):nuget push "你的包文件路径\xxx.nupkg" -ApiKey 你的NuGet密钥 -Source https://api.nuget.org/v3/index.json
内容的提问来源于stack exchange,提问作者Manoj Mandala
相关产品推荐
相关产品推荐

