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

时间:2015-10-21 21:18:19

标签: 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 ==========

3 个答案:

答案 0 :(得分:8)

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

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

编辑XML配置文件,评论协议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包。

答案 1 :(得分:0)

当我过去遇到Nuget问题时,这些是我已经完成的步骤:

1)使用Nuget包管理器删除项目

2)清理和构建(因为你有更长的引用,你会有错误 2)确保从packages.config中删除了包(如果没有,删除并重复步骤2)

3)确保.dll已从bin文件夹中删除(如果没有,请删除并重复步骤2)

4)重新添加包并重建。确保将包添加到packages.config(具有适当的版本)并将.dll添加回bin文件夹(具有适当的版本)。

答案 2 :(得分:0)

我正在运行VS 2017,但在&#34; dotnet恢复&#34;期间,TFS构建服务器出现此错误。任务。问题是我们有一个内部本地文件共享,但是nuget.config有protocolVersion =&#34; 3&#34;对于那个条目。删除该属性后,构建成功。