c# - Nuget - 对象引用未设置为对象的实例

标签 c# nuget visual-studio-2015 nuget-package

我在 vs 2015 中遇到了 nuget 包管理器的问题。
像 Unity 这样的一些软件包已经安装没有问题。
某些软件包(例如 EF)在安装时出现问题。
一些像 Automapper 这样的包也有同样的问题,但是当我安装这个包的另一个版本时,它安装得很好。

这是输出:

System.NullReferenceException: Object reference not set to an instance of an object.


at NuGet.Protocol.Core.v3.GlobalPackagesFolderUtility.<AddPackageAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at NuGet.Protocol.Core.v3.DownloadResourceV3.<GetDownloadResourceResultAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NuGet.PackageManagement.PackageDownloader.<GetDownloadResourceResultAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at NuGet.PackageManagement.NuGetPackageManager.<ExecuteNuGetProjectActionsAsync>d__42.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at NuGet.PackageManagement.NuGetPackageManager.<ExecuteNuGetProjectActionsAsync>d__42.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NuGet.PackageManagement.UI.UIActionEngine.<ExecuteActionsAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NuGet.PackageManagement.UI.UIActionEngine.<PerformActionAsync>d__3.MoveNext()
========== Finished ==========

最佳答案

使用 Visual Studio 2015 中使用的新协议(protocol)(版本 3)nuget 是一个常见问题。它与多个 nuget 包一起使用,例如 Microsoft.Owin 3.0.1。
要解决此问题,请访问:

C:\Users\<your user name>\AppData\Roaming\NuGet

并编辑 XML 配置文件,注释协议(protocol) 3 的行:
<!-- add key = "nuget.org" value = "https://api.nuget.org/v3/index.json" protocolVersion = "3" /-->
<add key = "nuget.org" value = "https://www.nuget.org/api/v2/" /> 

版本 2 的维护设置。保存并重新启动 Visual Studio 2015。您现在应该毫无问题地恢复 nuget 包。

关于c# - Nuget - 对象引用未设置为对象的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33269430/

相关文章:

c# - 我应该实现存储库和 xml 服务吗?

c# - 编译器会优化 bool 赋值吗?

azure - 无法加载源 https ://pkgs. dev.azure.com/xxxxx/_packaging/yyyyy/nuget/v3/index.json 的服务索引

package - 下载自托管源的 NuGet 包

nuget - 如何打包面向通用 Windows 平台并依赖于 Visual Studio 扩展 SDK 的 .NET 库?

c# - ToString 重载中未处理的异常

c# - LINQ 中的多个左连接

c# - 如何在我的 C# 代码中正确处理 Web 响应中的 UTF-8?

.net - Visual Studio 社区 2015 更新 1 生成问题

c++ - VS 2015 在预处理中使用 CLOCKS_PER_SEC 破坏代码