visual-studio - Visual Studio 2017-无法初始化Powershell主机

标签 visual-studio powershell nuget-package

第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 ...

再试一次...让我们看看能否使Package Manager控制台正常工作...

启动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 Installer ...
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

结果显示以下内容:

enter image description here

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

======

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

在最后(绝望)的尝试中,我启动了Visual Studio Installer
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

放弃 ...
  • UNINSTALLED Visual Studio。关机(关机系统)
  • 启动(加电系统)
  • 从以下位置下载了Visual Studio安装程序
    https://www.visualstudio.com/downloads/
  • 按照安装程序说明运行磁盘清理应用程序。
  • 关闭(关闭电源的系统)
  • 启动(加电系统)
  • 运行Visual Studio 2017社区安装程序-成功。
  • 启动Visual Studio
  • 工具-> 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主机的根本原因尚未解决。 。

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

    最佳答案

    关于visual-studio - Visual Studio 2017-无法初始化Powershell主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48837473/

    相关文章:

    c++ - native Nuget 包安装在 VS 中,但没有为 C++( native )项目添加引用

    visual-studio - Visual Studio : Where does it store "Set as startup project"?

    c++ - 如何使 'C4700: uninitialized local variable' 在 Release 模式下报错

    visual-studio - 为什么我的智能设备应用程序会创建 *.asmmeta.dll 文件?

    .net - 如何强制 Visual Studio 检查最新版本的浮点 nuget 依赖项

    将证书安装到 Active Directory 存储中的 Powershell 脚本

    powershell - 停止 Windows 服务时出错

    powershell - 安装 NuGet 包时如何向项目添加 AfterBuild 事件?

    powershell - DockerFile的一些问题

    nuget - 将文件从子文件夹复制到 nuspec 中的根目录