[英]Can't install nuget package because of “Failed to initialize the PowerShell host”
All of a sudden, I am getting this error when upgrading Nuget packages. 突然之间,升级Nuget软件包时出现此错误。 None of the fixes that I have come across work. 我遇到过的修复工作都没有。 I am using Visual Studio 2013. 我正在使用Visual Studio 2013。
'Newtonsoft.Json 6.0.3' already installed. 已经安装了“Newtonsoft.Json 6.0.3”。
Adding 'Newtonsoft.Json 6.0.3' to Tournaments.Notifications. 将“Newtonsoft.Json 6.0.3”添加到Tournaments.Notifications中。
Successfully added 'Newtonsoft.Json 6.0.3' to Tournaments.Notifications. 成功将“Newtonsoft.Json 6.0.3”添加到Tournaments.Notifications中。
Executing script file 'F:\\My Webs\\BasketballTournaments\\MainBranch\\packages\\Newtonsoft.Json.6.0.3\\tools\\install.ps1'. 执行脚本文件'F:\\ My Webs \\ BasketballTournaments \\ MainBranch \\ packages \\ Newtonsoft.Json.6.0.3 \\ tools \\ install.ps1'。
Failed to initialize the PowerShell host. 无法初始化PowerShell主机。 If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first. 如果PowerShell执行策略设置设置为AllSigned,请打开程序包管理器控制台以首先初始化主机。
Package Manager Console 包管理器控制台
Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failed. 尝试在“FileSystem”提供程序上执行InitializeDefaultDrives操作失败。
If I wait for the initialization to finish in the console I was able to add some packages. 如果我等待初始化在控制台中完成,我可以添加一些包。
Setting an execution policy to RemoteSigned or Unrestricted should work. 将执行策略设置为RemoteSigned或Unrestricted应该有效。 It must be changed under an administrator mode via a PowerShell console. 必须通过PowerShell控制台在管理员模式下进行更改。 Be aware that changes will be applied according to the bit version of the PowerShell console, so 32bit or 64 bit. 请注意,将根据PowerShell控制台的位版本应用更改,因此32位或64位。 So if you want to install a package in Visual Studio (32 bit version) which requires a specific policy you should change settings of the policy via PowerShell (x86). 因此,如果要在Visual Studio(32位版本)中安装需要特定策略的软件包,则应通过PowerShell(x86)更改策略的设置。
The command in PowerShell (as administrator) to set the policy to unrestricted (as noted by @Gabriel in the comments) is: PowerShell中的命令(作为管理员)将策略设置为不受限制(如评论中@Gabriel所述):
start-job { Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job
Having set the policy to unrestricted, you will want to set the policy back to its original after the install is complete. 将策略设置为不受限制后,您将需要在安装完成后将策略设置回原始策略。
Remember to restart Visual Studio after you've done the Set-ExecutionPolicy Unrestricted
in PowerShell (x86). 在PowerShell(x86)中完成Set-ExecutionPolicy Unrestricted
之后,请记住重新启动Visual Studio。
If that doesn't work, try Set-ExecutionPolicy RemoteSigned
in PowerShell (x86) then restart Visual Studio. 如果这不起作用,请在PowerShell(x86)中尝试Set-ExecutionPolicy RemoteSigned
,然后重新启动Visual Studio。
By default the PowerShell script execution is very limited for security reasons. 默认情况下,出于安全原因,PowerShell脚本执行非常有限。 For use within NuGet we need to open the doors. 要在NuGet中使用,我们需要打开门。
1. Step 1.步骤
Open Windows PowerShell
, run as Administrator
打开Windows PowerShell
,以Administrator
身份运行
2. Step 2.步骤
NuGet is using the 32 bit console, so it wont be affected by changes to the 64 bit console. NuGet正在使用32位控制台,因此它不会受到64位控制台更改的影响。 Run the following script to make sure you are configuring the 32 bit console. 运行以下脚本以确保您正在配置32位控制台。
start-job { Set-ExecutionPolicy RemoteSigned } -RunAs32 | wait-job | Receive-Job
3. Step 3.步骤
Restart Visual Studio
重新启动Visual Studio
I have the same issue with the Manage NuGet Packages dialog, I use a work-around that may help others - running from package manager console: 我在Manage NuGet Packages对话框中遇到了同样的问题,我使用了一个可以帮助其他人的解决方法 - 从包管理器控制台运行:
If I use the command line powershell commandlet install-package, all is fine. 如果我使用命令行powershell命令行安装包,一切都很好。
I am adverse to changing a security setting "just to make it work". 我不喜欢改变安全设置“只是为了让它工作”。
No answers have worked for me. 没有答案对我有用。
All policies were correct but I have the error when installing a package 所有策略都是正确的但我在安装软件包时遇到错误
Failed to initialize the PowerShell host. 无法初始化PowerShell主机。 If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first. 如果PowerShell执行策略设置设置为AllSigned,请打开程序包管理器控制台以首先初始化主机。
The solution : I have uninstalled the nuget package manager plugin and reinstalled it. 解决方案 :我已经卸载了nuget包管理器插件并重新安装了它。
以管理员身份运行Visual Studio为我工作。
我更新了Nuget包管理器并为我修复了它。
I had this issue with my Visual Studio 2015. I uninstalled and re-installed NuGet Package Manager again. 我的Visual Studio 2015出现了这个问题。我再次卸载并重新安装了NuGet Package Manager。 It worked for me. 它对我有用。
This started happening with 6.0.4 recently for me, I don't think this is a very good solution but here is what helped me. 最近我开始用6.0.4开始,我不认为这是一个非常好的解决方案,但这对我有帮助。 Close Visual Studio 关闭Visual Studio
I had the same problem after upgrading to Windows 10. 升级到Windows 10后,我遇到了同样的问题。
This worked for me 这对我有用
Set-ExecutionPolicy Unrestricted
运行Set-ExecutionPolicy Unrestricted
If it still doesn't work try editing devenv.exe.config
如果仍然无效,请尝试编辑devenv.exe.config
Visual Studio 2013: C:\\Users\\<UserName>\\AppData\\Local\\Microsoft\\VisualStudio\\12.0
Visual Studio 2013: C:\\Users\\<UserName>\\AppData\\Local\\Microsoft\\VisualStudio\\12.0
Visual Studio 2015: C:\\Users\\<UserName>\\AppData\\Local\\Microsoft\\VisualStudio\\14.0
Visual Studio 2015: C:\\Users\\<UserName>\\AppData\\Local\\Microsoft\\VisualStudio\\14.0
Add the following 添加以下内容
<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>
This Nuget fix worked for me: 这个Nuget修复对我有用:
https://github.com/NuGet/Home/issues/974#issuecomment-124774650 https://github.com/NuGet/Home/issues/974#issuecomment-124774650
By default my Windows 10 64-bit only had Powershell version 1.0 enabled. 默认情况下,我的Windows 10 64位仅启用了Powershell 1.0版。 I changed the control panel/Programs/Programs and features/Turn Windows features On Off. 我更改了控制面板/程序/程序和功能/关闭Windows功能。
Make sure the Windows Powershell 2.0 engine is enabled. 确保已启用Windows Powershell 2.0引擎。
Restart VS2015 in non-administrator mode and with all packages installed correctly. 以非管理员模式重新启动VS2015并正确安装所有软件包。
I had the same problem with vs2013 and changing execution policy did not fix it. 我和vs2013有同样的问题,更改执行策略没有解决它。 The only working solution I found was uninstalling Nuget from VS and installing it again. 我发现唯一可行的解决方案是从VS卸载Nuget并再次安装它。 Steps are here: https://stackoverflow.com/a/32619961/3853238 步骤如下: https : //stackoverflow.com/a/32619961/3853238
我需要做的就是重启Visual Studio,打开NuGet Package Manager Console
,然后使用Manage NuGet Packages
对话框。
Close all the visual studio instances and try again. 关闭所有可视工作室实例,然后重试。 It worked for me :) 它对我有用:)
After trying various suggested fixes, it was finally solved by updating the NuGet Package Manager extension in Visual Studio. 在尝试了各种建议的修复之后,最终通过在Visual Studio中更新NuGet Package Manager扩展来解决它。
This is done under Tools -> Extensions And Updates, then in the Extensions and Updates dialog Updated -> Visual Studio Gallery. 这在“工具” - >“扩展和更新”下完成,然后在“扩展和更新”对话框中更新 - > Visual Studio库。 A restart of Visual Studio may be required. 可能需要重新启动Visual Studio。
If you use VS 2013 Update 5, you should manually install an update 2.8.7 for NuGet Packet Manager. 如果您使用VS 2013 Update 5,则应手动为NuGet Packet Manager安装更新2.8.7 。
The bug report has more details. 错误报告有更多细节。
VS2015:更新了NuGet并且工作正常。
What did the trick for me was to re-install NuGet Package Manager by using the link below: 对我来说,诀窍是使用以下链接重新安装NuGet Package Manager:
VS 2013: https://github.com/NuGet/Home/releases/download/2.8.7/NuGet.Tools.vsix VS 2013: https : //github.com/NuGet/Home/releases/download/2.8.7/NuGet.Tools.vsix
VS 2015: https://github.com/NuGet/Home/releases/download/3.1.1/NuGet.Tools.vsix VS 2015: https : //github.com/NuGet/Home/releases/download/3.1.1/NuGet.Tools.vsix
If none of the above helps, see if you can update Visual Studio. 如果上述方法都不起作用,请查看是否可以更新Visual Studio。
I Had the same issue with Visual Studio 2017 Community when I tried to install Newtonsoft.Json. 当我尝试安装Newtonsoft.Json时,我在Visual Studio 2017社区中遇到了同样的问题。 The ExecutionPolicy
change didn't help (I tried using both PowerShell and Registry Editor). ExecutionPolicy
更改没有帮助(我尝试使用PowerShell和注册表编辑器)。 I also tried to uninstall and install NuGet. 我还尝试卸载并安装NuGet。
After running VS2017 setup file, it asked for update of Visual Studio. 运行VS2017安装文件后,它要求更新Visual Studio。 All the problems disappeared after the update. 更新后所有问题都消失了。
If the above answers dint work for you - 如果以上答案适合你 -
For me setting the execution policy to Unrestricted did not work. 对我来说,将执行策略设置为Unrestricted不起作用。 I had to repair the vs2013 installation by going into Control Panel. 我必须通过进入控制面板修复vs2013安装。 Repairing the installation worked for me. 修复安装对我有用。
有同样的问题,这解决了我(Powershell作为管理员):
Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\PowerShell -Name ExecutionPolicy -Value ByPass
after trying all the suggested solution nothing worked on VS 2015 update 2 在尝试了所有建议的解决方案后,VS 2015更新2没有任何效果
deleting the package folder from the solution folder and restoring it from visual studio worked for me 从解决方案文件夹中删除包文件夹并从visual studio恢复它对我有用
I had a similar problem. 我遇到了类似的问题。 I have fixed it by turning "Windows PowerShell 2.0" feature on in "Turn Windows features on or off". 我通过在“打开或关闭Windows功能”中打开“Windows PowerShell 2.0”功能来修复它。 Note that this feature is turned on by default, I manually turned it off few days ago. 请注意,默认情况下此功能处于启用状态,我几天前手动将其关闭。
I'm working on Windows 10 Pro 64bit and same problem was with Visual Studio 2015 and 2017 (32bit and 64bit app) 我正在使用Windows 10 Pro 64位,同样的问题是Visual Studio 2015和2017(32位和64位应用程序)
Download and Install Administrative Templates for Windows PowerShell 下载并安装Windows PowerShell的管理模板
Next: Powershell x86 from As Administrator
Run: Get-ExecutionPolicy -List , and see if you have RemoteSigned etc..
1. 5 different scopes Set-ExecutionPolicy "RemoteSigned" -Scope Process -Confirm:$false
2. Machine and User Policy you have to set through the Group Policy Administration Template in 2 areas.
UPDATE - EDIT: 更新 - 编辑:
Set ALL of them to "Undefined" and ONLY the LocalMachine to "Restricted"
This is what fixed might after I had given my powershell more permissions not knowing that it would mess up visual studio 2013 and 2015 这是固定可能在我给了我的powershell更多权限后不知道它会搞乱视觉工作室2013和2015
This issue is not always related to the PowerShell Execution Policy. 此问题并不总是与PowerShell执行策略相关。 My machine is configured as "Unrestricted" for both PowerShell x64 and x86, but I still get this error message from times to times in Visual Studio 2013. 我的计算机配置为PowerShell x64和x86的“Unrestricted”,但我仍然在Visual Studio 2013中不时收到此错误消息。
When I try to open the Package Manager Console: 当我尝试打开包管理器控制台时:
Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope. Windows PowerShell已成功更新您的执行策略,但该设置被更具体范围内定义的策略覆盖。 Due to the override, your shell will retain its current effective execution policy of Unrestricted. 由于覆盖,您的shell将保留其当前有效的Unrestricted执行策略。 Type "Get-ExecutionPolicy -List" to view your execution policy settings. 键入“Get-ExecutionPolicy -List”以查看执行策略设置。 For more information please see "Get-Help Set-ExecutionPolicy". 有关详细信息,请参阅“Get-Help Set-ExecutionPolicy”。
This is not a valid error message. 这不是有效的错误消息。
Rebooting Visual Studio does not always resolve the problem. 重新启动Visual Studio并不总能解决问题。
Running the process as an admin never resolves the problem. 以管理员身份运行该过程永远无法解决问题。
Like Declan, the latest update of the Package Manager plugin fixed the issue: 2.8.60723.765 与Declan一样,Package Manager插件的最新更新解决了这个问题:2.8.60723.765
Set the execution policy to Bypass instead of Unrestricted or RemoteSigned; 将执行策略设置为Bypass而不是Unrestricted或RemoteSigned; this tutorial gives fuller instructions . 本教程提供了更全面的说明 。 Also, if you are having trouble using PowerShell to change the policy then the author shows you how to change it in Regedit. 此外,如果您在使用PowerShell更改策略时遇到问题,那么作者会向您展示如何在Regedit中更改它。
There are an awful lot of stabs in the dark here, so I'll add my own. 黑暗中有很多刺伤,所以我会添加自己的刺。
In my case, I also got a message that there was a missing lock file, and a recommendation to run dnu restore
in the package manager console. 在我的情况下,我还收到一条消息,说有一个丢失的锁文件,并建议在包管理器控制台中运行dnu restore
。 I did so, restarted VS, and everything is now working. 我这样做了,重新启动了VS,现在一切正常。
What worked for me is: 对我有用的是:
Find-Module ISEModuleBrowserAddon | Install-Module
Import-Module ISEModuleBrowserAddon
Find-Module ISEScriptAnalyzerAddOn | Install-Module
Import-Module ISEScriptAnalyzerAddOn
Import-Module ScriptBrowser
Enable-ScriptBrowser
在ISE中,您需要Enable-ScriptBrowser
And you have Module, Script, and Analyser in your ISE. 您的ISE中有模块,脚本和分析器。
Run in Win 10 Pro, x64 Console Host 5.0.10586.122 在Win 10 Pro,x64控制台主机5.0.10586.122中运行
Good Luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.