以下信息是从此 Visual Studio NuGet 控制台错误报告票线程收集的:https://github.com/NuGet/Home/issues/1638
原因
根据 Yishai Galatzer (Microsoft) 的 this comment,该问题是由 System.Management.Automation 3.0 中的 PowerShell DLL 中的堆栈溢出错误引起的。带有错误的更新 DLL 显然是在过去几周的某个时候作为 Windows 更新的一部分分发的。
另外,根据 Yishai Galatzer 的 another comment,PowerShell 团队将在本月晚些时候(2016 年 1 月)发布针对此问题的修复程序。
解决方法/临时解决方案
“pete1208”posted 之前在同一线程中的以下解决方法:
在您的 Visual Studio 文件夹中,制作文件 devenv.exe.config 的备份副本。
然后,在原始 devenv.exe.config 文件中,在开头的 assemblyBinding 元素之后插入以下内容:
<!-- WORKAROUND START for NuGet Console error:
"The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception"
Author: pete1208 from https://github.com/NuGet/Home/issues/1638 -->
<dependentAssembly>
<assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Commands.Utility" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.ConsoleHost" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Commands.Management" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Security" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Commands.Diagnostics" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<!-- WORKAROUND END -->
(您可能需要您最喜欢的文本编辑器的管理员升级版本才能将文件保存到您的 Visual Studio 文件夹中。)
然后,重新启动 Visual Studio。
同样per Yishai Galatzer,此变通办法的效果是使用绑定重定向来强制加载 PowerShell 1.0。
我尝试了解决方法,它确实对我有用。我的 Visual Studio 2013 中的包管理器控制台再次正常运行。
我计划密切关注那个 NuGet 错误线程,一旦宣布带有 System.Management.Automation 修复的 Windows 更新已经上线,我将在我的 @ 中退出解决方法987654330@文件。
更新
根据 Yishai Galatzer(Microsoft)的说法,该修复程序已在 January 12, 2016 Windows Update 中发布。