突然,我在升级 Nuget 软件包时遇到此错误。我遇到的所有修复都不起作用。我使用的是 Visual Studio 2013。
'Newtonsoft.Json 6.0.3' already installed.
Adding 'Newtonsoft.Json 6.0.3' to Tournaments.Notifications.
Successfully added 'Newtonsoft.Json 6.0.3' to Tournaments.Notifications.
Executing script file 'F:\My Webs\BasketballTournaments\MainBranch\packages\Newtonsoft.Json.6.0.3\tools\install.ps1'.
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.
包管理器控制台
Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failed.
如果我等待控制台中的初始化完成,我就可以添加一些包。
最佳答案
将执行策略设置为 RemoteSigned 或 Unrestricted 应该可以。必须在管理员模式下通过 PowerShell 控制台进行更改。请注意,更改将根据 PowerShell 控制台的位版本(即 32 位或 64 位)应用。因此,如果您想在 Visual Studio(32 位版本)中安装需要特定策略的包,您应该通过 PowerShell (x86) 更改策略设置。
PowerShell(以管理员身份)中将策略设置为不受限制的命令(如 @Gabriel 在评论中所述)是:
start-job { Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job
将策略设置为不受限制后,您需要在安装完成后将策略设置回其原始状态。
关于powershell - 无法安装 nuget 包,因为 "Failed to initialize the PowerShell host",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23353951/