简体   繁体   English

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

[英]Visual Studio 2017 - Unable to initialize powershell host

Day 1: 第一天:

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

I have a website project that is making use of the WindowsAzure.Storage NuGet package. 我有一个网站项目正在使用WindowsAzure.Storage NuGet包。

From within Visual Studio, I do the following: 在Visual Studio中,执行以下操作:

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

The system displays 2 updates are available: 系统显示2个可用更新:

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

I select check the "Select all packages" checkbox and click the "Update" button. 我选中“选择所有软件包”复选框,然后单击“更新”按钮。

FAIL (Never had this happen before) !! 失败(之前从未发生过)!

Below is the output captured from Visual Studio: 下面是从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...

Error List Window shows: 错误列表窗口显示:

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 output from: Get-ExecutionPolicy -List output: Powershell输出来自:Get-ExecutionPolicy -List输出:

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

Is there a problem with the NuGet package itself or my system? NuGet软件包本身或我的系统是否有问题?

I have never had this issue before and after searching for a solution (none found so far) -- I am at the mercy of the NuGet / Visual Studio gods! 在寻找解决方案之前和之后,我从未遇到过这个问题(到目前为止尚未找到)-我受NuGet / Visual Studio的宠爱!

Thanks in advance. 提前致谢。

====== ======

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

Trying again... Lets see if we can get the Package Manager Console working... 再试一次...让我们看看能否使Package Manager控制台正常工作...

Start Visual Studio (Community 2017) 启动Visual Studio(社区2017)

TOOLS -> NuGet Package Manager -> Package Manager Console

Which results in the following being displayed: 结果显示以下内容:

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.

Back to the drawing board! 回到绘图板! Will continue looking for a solution... 将继续寻找解决方案...

So, let's try Visual Studio Installer... 因此,让我们尝试一下Visual Studio Installer ...

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

Which results in: 结果是:

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

I click on "View Log", which displays: 我单击“查看日志”,其中显示:

[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)

Ok - so somehow, my system has lost a dependent package (Component.PowerShellTools.VS2017) -- will try modify to see if I can add the package... 好的-以某种方式,我的系统丢失了一个依赖包(Component.PowerShellTools.VS2017)-将尝试修改以查看是否可以添加该包...

====== ======

Day 2 - 10:15 am (still at it) - current state -- at wits end... 第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

I do the following: 我执行以下操作:

TOOLS -> NuGet Package Manager -> Package Manager Console

Which results in the following being displayed: 结果显示以下内容:

在此处输入图片说明

If anyone (Microsoft) has a solution -- I would REALLY appreciate it ! 如果有人(微软)有解决方案,我将不胜感激!

====== ======

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

In one final (desperate) attempt, I Launched Visual Studio Installer 在最后(绝望)的尝试中,我启动了Visual Studio安装程序

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

After a couple of hours Visual Studio was (re)installed: 几个小时后,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

I then do the following (after lighting 12 candles and chanting "Bill-Bill-Bill")... 然后,我执行以下操作(点燃12支蜡烛并高喊“ Bill-Bill-Bill”之后)...

TOOLS -> NuGet Package Manager -> NuGet Manager Console

Result: 结果:

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.

I am doomed -- I cannot use Visual Studio until this is fixed. 我注定了-在此问题解决之前,我无法使用Visual Studio。

====== ======

Day 3 - 7:49 am 第3天-上午7:49

I see my issue has been Triaged by MSFT at: 我看到我的问题已被MSFT进行过分诊:

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

Have also tried the "solutions" from these resources: 还尝试了以下资源的“解决方案”:

https://developercommunity.visualstudio.com/content/problem/154563/failed-to-initialize-the-powershell-host.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 https://docs.microsoft.com/en-us/nuget/release-notes/known-issues#opening-package-manager-console-fails-with-objectsecurity-exception

Unfortunately, none of the above have helped to correct this issue. 不幸的是,上述所有方法都无法帮助解决此问题。

Most posts indicate a complete re-install of VS may be needed -- good grief!! 大多数帖子表明可能需要完全重新安装VS-太可惜了!!

Hoping a solution will be found that DOES NOT REQUIRE A COMPLETE RE-INSTALL! 希望找到一个不需要完全重新安装的解决方案!

====== ======

Day 3 - 1:54 pm 第3天-下午1:54

Gave up ... 放弃 ...

  1. UNINSTALLED Visual Studio. 未安装的Visual Studio。 Shutdown (powered down system) 关机(断电系统)
  2. Startup (powered up system) 启动(开机系统)
  3. Downloaded Visual Studio installer from https://www.visualstudio.com/downloads/ https://www.visualstudio.com/downloads/下载的Visual Studio安装程序
  4. Ran Disk Clean app as per installer instructions. 按照安装程序说明运行Disk Clean应用。
  5. Shutdown (powered down system) 关机(断电系统)
  6. Startup (powered up system) 启动(开机系统)
  7. Ran Visual Studio 2017 Community Installer - success. Ran Visual Studio 2017社区安装程序-成功。
  8. Start Visual Studio 启动Visual Studio
  9. TOOLS -> NuGet Package Manager -> Package Manager Console 工具-> NuGet软件包管理器->软件包管理器控制台

Result: 结果:

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.

So - not even a fresh installation of Visual Studio Community is solving this problem !!!! 所以-甚至没有全新安装的Visual Studio Community都可以解决此问题!

====== ======

Day 4 - 9:11 am 第4天-上午9:11

Late last night I opened a new issue at GitHub re PowerShell, see: 昨晚深夜,我在GitHub re PowerShell上发布了一个新期刊,请参阅:

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

This morning, found a reply and took the suggestion of lzybkr and disabled Powershell V2; 今天早上,找到一个答复并接受了lzybkr的建议并禁用了Powershell V2。 I posted the commands for disabling V2 on the GitHub post above. 我在上面的GitHub帖子上发布了禁用V2的命令。

The good news - I was able to update packages via NuGet again! 好消息 -我能够再次通过NuGet更新软件包!

The bad news - If I start Visual Studio and then do: 坏消息 -如果我启动Visual Studio,然后执行以下操作:

TOOLS -> NuGet Package Manager -> Package Manager Console

The console window opens, but simply hangs with the following message: 控制台窗口打开,但仅挂起并显示以下消息:

Initializing Powershell host...

I STILL have NO idea WHAT is causing this behavior within Visual Studio; 我仍然不知道是什么原因导致了Visual Studio中的这种行为。 but after 4 days, I am just considering myself lucky that I can (once again) update NuGet packages and get back to work. 但是经过4天,我只是觉得自己很幸运,我可以(再次)更新NuGet软件包并重新开始工作。

Although my "issue" of updating NuGet packages has (for the most part) been resolved, I still do not see this as a solution as the root cause of why Visual Studio / NuGet Package Manager Console cannot initialize the PowerShell host has NOT been resolved. 尽管我的更新NuGet软件包的“问题”已得到解决(大部分),但我仍然没有将其视为解决方案,因为Visual Studio / NuGet软件包管理器控制台无法初始化PowerShell主机的根本原因尚未解决。 。

Should anyone find the root cause, please post your solution. 如果有人找到了根本原因,请发布您的解决方案。

We have finally identified the root cause of the issue, and will be fixing in 15.8 release of Visual Studio. 我们终于确定了问题的根本原因,并将在Visual Studio的15.8版本中修复。

For now, the possible workarounds for this are: 现在,可能的解决方法是:

1) Install .NET 2.0 on your machine, which will install the System.Management.Automation Version=1.0.0 1)在您的计算机上安装.NET 2.0,这将安装System.Management.Automation版本= 1.0.0

2) Use the binding redirect as suggested by some of the members of the community in devenv.exe.config: 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>

Thanks, Rohit Agrawal NuGet Team 谢谢,Rohit Agrawal NuGet团队

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM