由于"无法初始化PowerShell主机",无法安装nuget包

Mik*_*ynn 171 powershell powershell-2.0 nuget nuget-package visual-studio-2013

突然之间,升级Nuget软件包时出现此错误.我遇到过的修复工作都没有.我正在使用Visual Studio 2013.

已经安装了"Newtonsoft.Json 6.0.3".

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

成功将"Newtonsoft.Json 6.0.3"添加到Tournaments.Notifications中.

执行脚本文件'F:\ My Webs\BasketballTournaments\MainBranch\packages\Newtonsoft.Json.6.0.3\tools\install.ps1'.

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

包管理器控制台

尝试在"FileSystem"提供程序上执行InitializeDefaultDrives操作失败.

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

小智 192

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

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

start-job { Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job
Run Code Online (Sandbox Code Playgroud)

将策略设置为不受限制后,您将需要在安装完成后将策略设置回原始策略.

  • 为我工作.当您在64位系统上更改PowerShell中的ExecutionPolicy时,它只会针对64位版本的PowerShell更改它.但VS是一个32位进程,而"程序包管理器控制台"也是一个32位进程.要解决此问题,您可以执行`start-job {Set-ExecutionPolicy Unrestricted} -RunAs32 | 等待工作 在64位PowerShell控制台中接收 - 作业`. (83认同)
  • 您需要在之后重新启动Visual Studio. (69认同)
  • 关闭VS 2013,以管理员身份运行,开始正常工作...... wiered (9认同)
  • 我在VS2015中遇到了这个问题,只是更新了NuGet paackage manager解决了这个问题 (9认同)

Sir*_*lih 55

Set-ExecutionPolicy Unrestricted在PowerShell(x86)中完成后,请记住重新启动Visual Studio .

如果这不起作用,请尝试Set-ExecutionPolicy RemoteSigned使用PowerShell(x86),然后重新启动Visual Studio.


Mic*_*der 51

默认情况下,出于安全原因,PowerShell脚本执行非常有限.要在NuGet中使用,我们需要打开门.

1.步骤

打开Windows PowerShell,运行为Administrator

2.步骤

NuGet正在使用32位控制台,因此它不会受到64位控制台更改的影响.运行以下脚本以确保您正在配置32位控制台.

start-job { Set-ExecutionPolicy RemoteSigned } -RunAs32 | wait-job | Receive-Job
Run Code Online (Sandbox Code Playgroud)

3.步骤

重新开始 Visual Studio


All*_*lan 25

我在Manage NuGet Packages对话框中遇到了同样的问题,我使用了一个可以帮助其他人的解决方法 - 从包管理器控制台运行:

如果我使用命令行powershell命令行安装包,一切都很好.

我不喜欢改变安全设置"只是为了让它工作".

  • 我认为这不是一个新问题,因为它与提出的问题直接相关.我对这篇文章进行了重写,以便听起来不像是一个新问题,而是一个心怀不满的开发者的沉思. (3认同)

Tro*_*ers 24

没有答案对我有用.

所有策略都是正确的但我在安装软件包时遇到错误

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

解决方案:我已经卸载NuGet包管理器插件,并重新安装它.

  • 卸载和重新安装是唯一有帮助的事情.此问题也在此处描述:https://github.com/NuGet/Home/issues/974 (4认同)
  • 我重新安装了NuGet VSIX软件包而没有首先卸载它,这解决了这个问题. (2认同)

Sud*_*hir 16

以管理员身份运行Visual Studio为我工作.

  • 同上,尽管人们应该记住在安装包后关闭 VS,并在常规权限下重新打开。 (2认同)

Dec*_*McD 7

我更新了Nuget包管理器并为我修复了它.


Hen*_*y.K 7

我的Visual Studio 2015出现了这个问题.我再次卸载并重新安装了NuGet Package Manager.它对我有用.


小智 6

最近我开始用6.0.4开始,我不认为这是一个非常好的解决方案,但这对我有帮助.关闭Visual Studio

  1. 以管理员身份打开Windows PowerShell提示符(非常重要)并运行以下命令:Set-ExecutionPolicy Bypass
  2. 打开Visual Studio,打开解决方案并使用Nuget安装JSON.Net(或任何包含它作为依赖项的包).
  3. 一切正常后,我建议使用以下命令将powershell执行策略设置为受限制:Set-ExecutionPolicy Restricted


小智 6

如果以上答案对您有用 -

  1. 打开运行-windows + R
  2. 打开注册表编辑器 - 键入 regedit.exe
  3. 打开 - HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\PowerShell
  4. 在右侧窗格中 - 修改“ExecutionPolicy”并将其“Value Data”保留为空白。
  5. 重新启动您的 Visual Studio,现在您的 Powershell 可以正确初始化。


Beh*_*inA 5

升级到Windows 10后,我遇到了同样的问题.

这对我有用

  1. 关闭Visual Studio
  2. 以管理员身份运行Powershell
  3. Set-ExecutionPolicy Unrestricted
  4. 以管理员身份运行Visual Studio
  5. 清理项目并添加nuget包

如果仍然无效,请尝试编辑 devenv.exe.config

Visual Studio 2013: C:\Users\<UserName>\AppData\Local\Microsoft\VisualStudio\12.0

Visual Studio 2015: C:\Users\<UserName>\AppData\Local\Microsoft\VisualStudio\14.0

添加以下内容

    <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>
Run Code Online (Sandbox Code Playgroud)