【问题标题】:Visual Studio 2017 - Unable to initialize powershell hostVisual Studio 2017 - 无法初始化 powershell 主机
【发布时间】:2018-04-28 01:37:20
【问题描述】:

第 1 天:

System: Windows 10
Microsoft Visual Studio Community 2017 
Version 15.5.5
VisualStudio.15.Release/15.5.5+27130.2026

我有一个使用 WindowsAzure.Storage NuGet 包的网站项目。

在 Visual Studio 中,我执行以下操作:

Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution ...

系统显示有 2 个更新可用:

Newtonsoft.Json v10.0.3 (currently installed v9.0.1)
WindowsAzure.Storage v9.0 (currently installed v8.7)

我选择选中“选择所有包”复选框并单击“更新”按钮。

失败(以前从未发生过这种情况)!!

以下是从 Visual Studio 捕获的输出:

Retrieving package 'WindowsAzure.Storage 9.0.0' from 'nuget.org'.
...
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3007) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3014) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3021) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3028) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3035) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The term 'Get-ExecutionPolicy' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Install failed. Rolling back...

错误列表窗口显示:

Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.

Powershell 输出来自:Get-ExecutionPolicy -List 输出:

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser    Unrestricted
 LocalMachine    Unrestricted

NuGet 包本身或我的系统是否有问题?

在寻找解决方案之前和之后我从来没有遇到过这个问题(目前还没有找到)——我受制于 NuGet / Visual Studio 之神!

提前致谢。

======

第 2 天:上午 8:00 ...

再试一次......让我们看看我们是否可以让包管理器控制台工作......

启动 Visual Studio(社区 2017)

TOOLS -> NuGet Package Manager -> Package Manager Console

这会导致显示以下内容:

The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3007) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3014) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3021) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3028) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3035) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The term 'Get-ExecutionPolicy' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

回到绘图板!将继续寻找解决方案...

那么,让我们试试 Visual Studio 安装程序...

Launch Visual Studio Installer
Select "More" -> "Repair"

结果:

The dependent package cannot be found: Component.PowerShellTools.VS2017,version=3.0.585

我点击“查看日志”,显示:

[1cb4:000a][2018-02-17T08:27:06] Error 0x80131500: The dependent package cannot be found: Component.PowerShellTools.VS2017,version=3.0.585
   at Microsoft.VisualStudio.Setup.Dependencies.DependencyManager.FindDependentPackages(Dependency dependency, DependencyComparer comparer, Dictionary`2 packageIndex)
   at Microsoft.VisualStudio.Setup.Dependencies.DependencyManager.BuildGraphRecursive(IPackage graphRoot, DependencyNode node, DependencyComparer comparer, Dictionary`2 packageIndex, Dictionary`2 nodeIndex, Boolean splitNodes)
   at Microsoft.VisualStudio.Setup.Dependencies.DependencyManager.BuildGraphCore(IPackage root, IEnumerable`1 packages, DependencyComparer comparer, Dictionary`2 packageIndex, Dictionary`2 nodeIndex, Boolean splitNodes, DependencyCollection deprecated)
   at Microsoft.VisualStudio.Setup.Dependencies.DependencyManager.BuildGraph(IPackage root, IEnumerable`1 packages, Boolean isUpdate, IDependencyComparisonSeed seed, DependencyCollection deprecated)
   at Microsoft.VisualStudio.Setup.Engine.GetDependencyGraph(Product product)
   at Microsoft.VisualStudio.Setup.Engine.PreChecks(String installationPath, Boolean isLayoutSet, Product product, ExecuteAction bootstrapperAction, ITelemetryOperation operation, IQuery query)
   at Microsoft.VisualStudio.Setup.Engine.Repair(CancellationToken token)

好的 - 不知何故,我的系统丢失了一个依赖包 (Component.PowerShellTools.VS2017) - 将尝试修改以查看是否可以添加包...

======

第 2 天 - 上午 10:15(仍在进行中) - 当前状态 - 智慧结束...

Microsoft Visual Studio Community 2017 
Version 15.5.6
VisualStudio.15.Release/15.5.6+27130.2027
Microsoft .NET Framework
Version 4.7.02556

我执行以下操作:

TOOLS -> NuGet Package Manager -> Package Manager Console

这会导致显示以下内容:

如果有人(微软)有解决方案——我将不胜感激!

======

第 2 天:下午 3:09 ...

在最后一次(绝望的)尝试中,我启动了 Visual Studio 安装程序

Click on "More" -> "Repair" ....

几个小时后,Visual Studio 被(重新)安装了:

Microsoft Visual Studio Community 2017 
Version 15.5.6
VisualStudio.15.Release/15.5.6+27130.2027
Microsoft .NET Framework
Version 4.7.02556

然后我执行以下操作(点燃 12 支蜡烛并高呼“Bill-Bill-Bill”之后)...

TOOLS -> NuGet Package Manager -> NuGet Manager Console

结果:

The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3007) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3014) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3021) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3028) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3035) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The term 'Get-ExecutionPolicy' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

我注定要失败 - 在此问题解决之前我无法使用 Visual Studio。

======

第 3 天 - 上午 7:49

我看到我的问题已被 MSFT 分类:

https://developercommunity.visualstudio.com/content/problem/199976/visual-studio-failed-to-initialize-the-powershell.html

还尝试了这些资源中的“解决方案”:

https://developercommunity.visualstudio.com/content/problem/154563/failed-to-initialize-the-powershell-host.html

https://docs.microsoft.com/en-us/nuget/release-notes/known-issues#opening-package-manager-console-fails-with-objectsecurity-exception

很遗憾,以上方法均无助于纠正此问题。

大多数帖子都表明可能需要完全重新安装 VS —— 天哪!!

希望找到一个不需要完全重新安装的解决方案!

======

第 3 天 - 下午 1:54

放弃...

  1. 卸载 Visual Studio。关机(关闭系统)
  2. 启动(启动系统)
  3. 从下载的 Visual Studio 安装程序 https://www.visualstudio.com/downloads/
  4. 按照安装程序说明运行磁盘清理应用程序。
  5. 关机(系统断电)
  6. 启动(启动系统)
  7. 运行 Visual Studio 2017 社区安装程序 - 成功。
  8. 启动 Visual Studio
  9. 工具 -> NuGet 包管理器 -> 包管理器控制台

结果:

The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3007) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3014) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3021) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3028) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(3035) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
The term 'Get-ExecutionPolicy' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

所以 - 即使是全新安装的 Visual Studio Community 也无法解决这个问题!!!!

======

第 4 天 - 上午 9:11

昨晚我在 GitHub re PowerShell 上打开了一个新问题,请参阅:

https://github.com/PowerShell/PowerShell/issues/6189

今天早上找到回复,采纳lzybkr的建议,禁用Powershell V2;我在上面的 GitHub 帖子上发布了禁用 V2 的命令。

好消息 - 我能够再次通过 NuGet 更新软件包!

坏消息 - 如果我启动 Visual Studio 然后:

TOOLS -> NuGet Package Manager -> Package Manager Console

控制台窗口打开,但只是挂起并显示以下消息:

Initializing Powershell host...

我仍然不知道是什么导致了 Visual Studio 中的这种行为;但 4 天后,我只是觉得自己很幸运,我可以(再次)更新 NuGet 包并重新开始工作。

虽然我更新 NuGet 包的“问题”(大部分)已经解决,但我仍然不认为这是一个解决方案,这是导致 Visual Studio / NuGet 包管理器控制台无法初始化 PowerShell 主机的根本原因未解决。

如果有人找到根本原因,请发布您的解决方案。

【问题讨论】:

  • 我的同情。上周我经历了类似的考验——涉及 VS、Azure 和 NuGet 的多方版本控制 catch-22。我通读了你的问题,但似乎不是一回事。坦率地说,到最后我已经筋疲力尽了,我不确定我会得到多少帮助。
  • 天哪!谢谢你的评论——看来我要去地狱了!顺便说一句 - 我刚刚将 Visual Studio 更新到 15.5.6 - 结果相同。啊!
  • 我在磨难的中途也做了同样的升级。就我而言,这使事情变得更加复杂,因为您知道关于中途换马的说法。希望您的问题没有那么多活动部分。

标签: visual-studio powershell nuget-package


【解决方案1】:

【讨论】:

  • 这救了我。我尝试了许多解决方案,但没有一个有效。最后这个工作。我使用 Visual Studio Professional 15.6.4(截至本文的最新版本)
  • 当我的机器上再次发生这种情况时,此解决方案无法正常工作。我什至重新安装了 vs 2017。后来我成功地使用了这个解决方案:developercommunity.visualstudio.com/content/problem/35803/… 这很相似,只是它是为当前用户而不是为管理员完成的,并且它包含更多项目。
  • 我在 Visual Studio Professional 2019 16.4.0 上遇到了同样的问题。从链接的 MS 开发人员社区帖子中,不清楚应该在 AppData\Local\Microsoft\VisualStudio` the devenv.exe.config` 文件下的哪个文件夹中进行编辑。我尝试了唯一一个名称以 16 开头的文件夹(特别是 16.0_0c833e6b),但没有帮助
  • 我在 VS2019 上试过这个,但没用。
【解决方案2】:

我们终于确定了问题的根本原因,并将在 Visual Studio 15.8 版本中修复。

目前,可能的解决方法是:

1) 在您的机器上安装 .NET 2.0,这将安装 System.Management.Automation Version=1.0.0

2) 使用一些社区成员在 devenv.exe.config 中建议的绑定重定向:

<dependentAssembly>
   <assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
    <publisherPolicy apply="no" />
   </dependentAssembly>

谢谢, 罗希特·阿格拉瓦尔 NuGet 团队

【讨论】:

  • 这在 15.9.3 版中仍然适用。它尚未修复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-14
  • 2015-05-27
  • 1970-01-01
  • 1970-01-01
  • 2013-03-14
  • 1970-01-01
相关资源
最近更新 更多