Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't install nuget package because of "Failed to initialize the PowerShell host"

People also ask

How do I Install a NuGet package in PowerShell?

Open PowerShell as administrator. Run the command Install-Module PowerShellGet -Force to install the NuGet package. When asked for confirmation to install the NuGet provider, press the Y key and press Enter .

How do I force a NuGet package to Install?

Switch to the Browse tab, search for the package name, select it, then select Install). For all packages, delete the package folder, then run nuget install . For a single package, delete the package folder and use nuget install <id> to reinstall the same one.

Can not Install NuGet?

Solution for unable to install NuGet provider for PowerShellRun both cmdlets to set . NET Framework strong cryptography registry keys. After that, restart PowerShell and check if the security protocol TLS 1.2 is added. As of last, install the PowerShellGet module.


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).

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.


Remember to restart Visual Studio after you've done the Set-ExecutionPolicy Unrestricted in PowerShell (x86).

If that doesn't work, try Set-ExecutionPolicy RemoteSigned in PowerShell (x86) then restart Visual Studio.


By default the PowerShell script execution is very limited for security reasons. For use within NuGet we need to open the doors.

1. Step

Open Windows PowerShell, run as Administrator

2. Step

NuGet is using the 32 bit console, so it wont be affected by changes to the 64 bit console. Run the following script to make sure you are configuring the 32 bit console.

start-job { Set-ExecutionPolicy RemoteSigned } -RunAs32 | wait-job | Receive-Job

3. Step

Restart 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:

If I use the command line powershell commandlet install-package, all is fine.

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. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.

The solution : I have uninstalled the nuget package manager plugin and reinstalled it.


Running the Visual Studio as Administrator worked for me.


I had this issue with my Visual Studio 2015. I uninstalled and re-installed NuGet Package Manager again. It worked for me.