powershell - 无法安装 nuget 包,因为 "Failed to initialize the PowerShell host"

标签 powershell visual-studio-2013 nuget powershell-2.0 nuget-package

突然,我在升级 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/

相关文章:

.net - Powershell 3.0中的SOAP语法

git - 为什么 visual studio 在我的 .gitignore 文件中提交文件?

visual-studio - 广泛安装 Nuget 包解决方案

Powershell 默认参数集不起作用。错误

function - 如何在调用者的上下文中调用脚本 block ?

c++ - #import 指令创建的 COM 包装器类用 unsigned short 替换 wchar_t

c++ - 枚举类 : does not name a value error

.net - 引用不属于 .NET Standard 的程序集

visual-studio-2013 - 有没有办法在 Visual Studio 中自动更新已安装的 NuGet 包?

amazon-web-services - AWS Cloudformation Userdata powershell 脚本未在自定义 Windows Server AMI 上运行