管理 Nuget 包崩溃 VS2017

Manage Nuget Packages crashes VS2017

我每次添加 Nuget 引用时都会 Visual Studio 崩溃。感觉是个BUG

已向开发者社区(测试版)网站报告:https://developercommunity.visualstudio.com/content/problem/6782/manage-nuget-packages-crashes-vs2017rc.html

它说它是固定的,所以这个的确切根本原因一定是不同的:

这个问题看起来早在 2015 年就存在了,但没有答案:Nuget Package Manager crashes when clicking "Manage nuget packages for solution" Visual Studio 2015

太烦人了,我不得不使用控制台安装包或手动编辑 packages.config 文件,然后恢复包。不开心 - 有人有解决方案吗?

规格
Win7 x64
微软 Visual Studio 企业版 2017
版本 15.2 (26430.6) 发布
VisualStudio.15.Release/15.2.0+26430.6
Microsoft .NET 框架 v 4.7.02053

已安装版本:企业版

.....

NuGet 包管理器 4.2.0


事件日志:

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.UnauthorizedAccessException
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.VisualStudio.Shell.Settings.ShellWritableSettingsStore.CreateCollection(String collectionPath)
   at Microsoft.VisualStudio.PlatformUI.CategoryMRUItems.SaveItems(WritableSettingsStore store)
   at Microsoft.VisualStudio.PlatformUI.MRUItemsStoreService.AddMRUItem(Guid& guidCategory, String lpszItem)
   at Microsoft.VisualStudio.PlatformUI.MruItemsStoreServiceDecorator.AddMRUItem(Guid& guidCategory, String lpszItem)
   at Microsoft.VisualStudio.Platform.WindowManagement.WindowSearchHost.Microsoft.VisualStudio.Platform.WindowManagement.IWindowSearchEventsHandler.OnAddMRUItem(String searchedText)
   at Microsoft.VisualStudio.Platform.WindowManagement.WindowSearchDataSource.OnAddMRUItem(String searchedText)
   at Microsoft.VisualStudio.PlatformUI.SearchControlDataSource.AddMRUItemAction(GelDependencyObject datasource, Object parameter)
   at Microsoft.Internal.VisualStudio.PlatformUI.GelDependencyObject.Invoke(GelVerb descriptor, Object param)
   at Microsoft.Internal.VisualStudio.PlatformUI.GelDependencyObject.Invoke(String verb, Object param)
   at Microsoft.Internal.VisualStudio.PlatformUI.GelDependencyObject.Invoke(String verb, Object pvaIn, Object& pvaOut)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32, IntPtr)
   at Microsoft.Internal.VisualStudio.PlatformUI.Utilities.Invoke(Microsoft.VisualStudio.Shell.Interop.IVsUIDataSource, System.String, System.Object)
   at Microsoft.VisualStudio.PlatformUI.SearchControl.AddToMRUItems(System.String)
   at Microsoft.VisualStudio.PlatformUI.SearchControl.SearchBox_LostKeyboardFocus(System.Object, System.Windows.Input.KeyboardFocusChangedEventArgs)
   at System.Windows.Input.KeyboardFocusChangedEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)
   at System.Windows.Input.KeyboardDevice.ChangeFocus(System.Windows.DependencyObject, Int32)
   at System.Windows.Input.KeyboardDevice.TryChangeFocus(System.Windows.DependencyObject, System.Windows.Input.IKeyboardInputProvider, Boolean, Boolean, Boolean)
   at System.Windows.Input.KeyboardDevice.Focus(System.Windows.DependencyObject, Boolean, Boolean, Boolean)
   at System.Windows.Input.KeyboardDevice.Focus(System.Windows.IInputElement)
   at System.Windows.UIElement.Focus()
   at System.Windows.Controls.ListBoxItem.HandleMouseButtonDown(System.Windows.Input.MouseButton)
   at System.Windows.Controls.ListBoxItem.OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs)
   at System.Windows.UIElement.OnMouseLeftButtonDownThunk(System.Object, System.Windows.Input.MouseButtonEventArgs)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject, System.Windows.RoutedEventArgs, System.Windows.RoutedEvent)
   at System.Windows.UIElement.OnMouseDownThunk(System.Object, System.Windows.Input.MouseButtonEventArgs)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.ContentElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)
   at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawMouseActions, Int32, Int32, Int32)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr, MS.Internal.Interop.WindowMessage, IntPtr, IntPtr, Boolean ByRef)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

Faulting application name: devenv.exe, version: 15.0.26430.6, time stamp: 0x5914d7fe
Faulting module name: KERNELBASE.dll, version: 6.1.7601.23807, time stamp: 0x5915f98e
Exception code: 0xe0434352
Fault offset: 0x0000c54f
Faulting process id: 0xf48
Faulting application start time: 0x01d2fb77b5f33dcc
Faulting application path: C:\Program Files x86\Microsoft Visual Studio17\Enterprise\Common7\IDE\devenv.exe
Faulting module path: C:\WINDOWS\syswow64\KERNELBASE.dll
Report Id: f949036c-676b-11e7-8422-3417ebddc764

Error Handler Exception: System.ServiceModel.CommunicationException: There was an error reading from the pipe: Unrecognized error 109 (0x6d). ---> System.IO.IOException: The read operation failed, see inner exception. ---> System.ServiceModel.CommunicationException: There was an error reading from the pipe: Unrecognized error 109 (0x6d). ---> System.IO.PipeException: There was an error reading from the pipe: Unrecognized error 109 (0x6d).
   at System.ServiceModel.Channels.PipeConnection.OnAsyncReadComplete(Boolean haveResult, Int32 error, Int32 numBytes)
   --- End of inner exception stack trace ---
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ConnectionStream.EndRead(IAsyncResult asyncResult)
   at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
   --- End of inner exception stack trace ---
   at System.Net.Security.NegotiateStream.EndRead(IAsyncResult asyncResult)
   at System.ServiceModel.Channels.StreamConnection.EndRead()
   --- End of inner exception stack trace ---
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.TransportDuplexSessionChannel.EndTryReceive(IAsyncResult result, Message& message)
   at System.ServiceModel.Dispatcher.DuplexChannelBinder.EndTryReceive(IAsyncResult result, RequestContext& requestContext)
   at System.ServiceModel.Dispatcher.ErrorHandlingReceiver.EndTryReceive(IAsyncResult result, RequestContext& requestContext) \r\n    at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.TransportDuplexSessionChannel.EndTryReceive(IAsyncResult result, Message& message)
   at System.ServiceModel.Dispatcher.DuplexChannelBinder.EndTryReceive(IAsyncResult result, RequestContext& requestContext)
   at System.ServiceModel.Dispatcher.ErrorHandlingReceiver.EndTryReceive(IAsyncResult result, RequestContext& requestContext)

我的 VS2017 在 NuGet 包管理器中也崩溃了,所以我无法将包添加到项目中。尝试以管理员身份启动 VS2017,我的让我以这种方式添加包,然后以普通用户身份重新启动 VS2017。

我使用 SysInternals Process Monitor 发现实际的 ACCESS_DENIED 发生在 VS 尝试 RegCreateKey 键时:

\REGISTRY\A\{4B5F9AD2-BB8B-4CF8-9ACB-201C56F4D086}\Software\Microsoft\VisualStudio.0_05fc10d7\MRUItems\{00000000-0000-0000-0000-000000000000}\Items

此密钥似乎存储在 VS 应用程序配置单元文件中:

C:\Users\<user name>\AppData\Local\Microsoft\VisualStudio.0_05fc10d7\privateregistry.user.bin

我以管理员身份启动 regedit,以 described:

将配置单元文件加载到注册表中
  1. 启动RegEdit.exe
  2. Select 左侧窗格中的 Computer\HKEY_LOCAL_MACHINE 节点
  3. Select 文件 | Load Hive... 菜单项,并加载 privateregistry.user.bin
  4. 当系统提示输入密钥名称时,只需输入类似 "VSRegHive"
  5. 的内容
  6. 这会将数据加载到 HKLM 节点下的 VSRegHive 中
  7. 创建 2 个缺失的键 {00000000-0000-0000-0000-000000000000}\Items:

  1. 完成后 select VSRegHive 和 select 文件 |卸载 Hive...,在退出 RegEdit.exe 实用程序之前,否则 VS 将无法启动。在 regedit 中保持 hive 加载会创建一些 某种阻止 DevEnv.exe 启动的锁。

由于缺少 2 个键,VS2017 不会在 NuGet 管理器中崩溃。