由于“无法初始化 PowerShell 主机"而无法安装 nuget 包 [英] Can't install nuget package because of "Failed to initialize the PowerShell host"

查看:38
本文介绍了由于“无法初始化 PowerShell 主机"而无法安装 nuget 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

突然间,我在升级 Nuget 包时遇到了这个错误.我遇到的所有修复都不起作用.我正在使用 Visual Studio 2013.

All of a sudden, I am getting this error when upgrading Nuget packages. None of the fixes that I have come across work. I am using Visual Studio 2013.

'Newtonsoft.Json 6.0.3' 已安装.

'Newtonsoft.Json 6.0.3' already installed.

将Newtonsoft.Json 6.0.3"添加到 Tournaments.Notifications.

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.

正在执行脚本文件 'F:My WebsBasketballTournamentsMainBranchpackagesNewtonsoft.Json.6.0.3 oolsinstall.ps1'.

Executing script file 'F:My WebsBasketballTournamentsMainBranchpackagesNewtonsoft.Json.6.0.3 oolsinstall.ps1'.

无法初始化 PowerShell 主机.如果您的 PowerShell 执行策略设置为 AllSigned,请先打开包管理器控制台初始化主机.

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.

包管理器控制台

尝试对文件系统"提供程序执行 InitializeDefaultDrives 操作失败.

Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failed.

如果我在控制台中等待初始化完成,我可以添加一些包.

If I wait for the initialization to finish in the console I was able to add some packages.

推荐答案

将执行策略设置为 RemoteSigned 或 Unrestricted 应该可以.它必须在管理员模式下通过 PowerShell 控制台进行更改.请注意,更改将根据 PowerShell 控制台的位版本应用,因此是 32 位或 64 位.因此,如果您想在需要特定策略的 Visual Studio(32 位版本)中安装包,您应该通过 PowerShell (x86) 更改策略设置.

Setting an execution policy to RemoteSigned or Unrestricted should work. It must be changed under an administrator mode via a PowerShell console. Be aware that changes will be applied according to the bit version of the PowerShell console, so 32bit or 64 bit. 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).

PowerShell(以管理员身份)将策略设置为不受限制的命令(如@Gabriel 在评论中所述)是:

The command in PowerShell (as administrator) to set the policy to unrestricted (as noted by @Gabriel in the comments) is:

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.

这篇关于由于“无法初始化 PowerShell 主机"而无法安装 nuget 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆