Visual Studio Package Installation Error: "Failed to initialize the PowerShell host."

1

I'm facing this error when I'm trying to create a webApplication Project, a message like below appears:

Package Installation Error

Could not add all required packages to the project. Thw following packages failed to install from 'C:\Program Files (x86)\Michrosoft Web Tools\Packages':

Microsoft.Web.Infrastructure.1.0.0.0: 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.
jQuery.1.10.2: 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.
Modernizr.2.6.2: 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.
Newtonsoft.Json.6.0.4: 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.

Also, after clicking OK it will continue creating the project but in the last step I have this Error message also:

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.

After all, in Package Manager Console I have this strange message appear:

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

visual-studio
visual-studio-2015
asked on Stack Overflow Feb 16, 2017 by Mohammad Saffarini • edited Jun 20, 2020 by Community

3 Answers

3

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.

answered on Stack Overflow Feb 16, 2017 by Amit Kumar Verma
1

reinstall -> run the program as administrator -> connect your laptop / desktop to internet for any update or downloadable files.

answered on Stack Overflow Feb 16, 2017 by ZZZ
1

I use Visual Studio 2019. Nuget packages failed to install and I got a similar error message. Since the error message says

'open the Package Manager Console to initialize the host first' 

it can be opened from

View >Other windows >Package Manager Console

for me it was greyed out and the the PMC displayed message

'Registry access denied'

Since new version of Powershells do not replace older existing version and PMC is a powershell console, I believe that execution policy must be set in the PMC.

Starting Visual Studio as administrator solved the problem for me without changing execution policy.

Also see, https://blog.jsinh.in/nuget-install-update-error-failed-to-initialize-the-powershell-host/ https://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio

answered on Stack Overflow Apr 28, 2021 by Anil • edited Apr 28, 2021 by Ann Zen

User contributions licensed under CC BY-SA 3.0