![](/img/trans.png)
[英]Visual Studio 2019: Failed to initialize the powershell host
[英]Visual Studio 2017 - Unable to initialize powershell host
第一天:
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
結果顯示以下內容:
如果有人(微軟)有解決方案,我將不勝感激!
======
第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進行過分診:
還嘗試了以下資源的“解決方案”:
不幸的是,上述所有方法都無法幫助解決此問題。
大多數帖子表明可能需要完全重新安裝VS-太可惜了!!
希望找到一個不需要完全重新安裝的解決方案!
======
第3天-下午1:54
放棄 ...
結果:
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的15.8版本中修復。
現在,可能的解決方法是:
1)在您的計算機上安裝.NET 2.0,這將安裝System.Management.Automation版本= 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>
謝謝,Rohit Agrawal NuGet團隊
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.