21

Whenever I create a new MVC project, I am getting an error - failed to initialize Powershell host, for the entity framework and Jquery. The error: The following packages failed to install from 'C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 4\Packages'

EntityFramework.5.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.7.1.1: 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.

I can remove the Entity Framework reference, and add it manually, which is a good workaround, but it is annoying and a sign of some problem somewhere. Any ideas where to look?

This link documents a similar problem and workaround: http://social.msdn.microsoft.com/Forums/en/vssetup/thread/c934fed4-e44e-4a06-9e3b-eccb9c8aa8d6

tereško
  • 58,060
  • 25
  • 98
  • 150
aSkywalker
  • 1,381
  • 1
  • 13
  • 23

6 Answers6

17

One of the replies on the MSDN thread worked for me. Run PowerShell as an Administrator and run the following command:

Set-ExecutionPolicy AllSigned

See Using the Set-ExecutionPolicy Cmdlet for security implications.

jrummell
  • 42,637
  • 17
  • 112
  • 171
  • Had same message: "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." This occured when trying to update Microsoft.WindowsAzure.Caching from 2.3.0.0. to 2.3.1.0. This solution helped me. – huha Apr 08 '14 at 07:53
  • 2
    I had to restart VS 2013, open the powershell console, select "A" for always run, then restart VS 2013 AGAIN to get this setting to work – mikebridge Apr 25 '14 at 05:14
  • Also make sure you execute this in the 32 and 64 bit PowerShell – Stef Heyenrath Aug 30 '14 at 11:19
  • I had to restart VS after making the above change, presumably so the Package Manager Console within VS could restart with the change taken into account. – Jamie Keeling Mar 24 '15 at 14:00
  • I second Jamie's solution. I ran the executionpolicy command and restarted VS. – Scope Creep May 09 '16 at 18:03
15

This problem is fairly common - as there are multiple links to the MSDN forums and references to the workaround. I tried troubleshooting with the Package Manager in Visual Studio and noticed that it was frozen - with a reference to looking for C:\Program Files (x86)\7-Zip\7z.exe. No idea why, but I checked my system and sure enough, I have 7z installed in the standard Program Files (not x86). I made a copy in the x86 folder, reloaded Visual Studio and Visual Studio is now happy again. Not sure why there is a dependancy on 7zip in the Visual Studio Package Manager - but hopefully this will help another programmer ...

aSkywalker
  • 1,381
  • 1
  • 13
  • 23
  • im not sure why you got bombed on this Q. Good detective work. – Dave Alperovich Jan 26 '13 at 21:24
  • Thanks for the positive feedback. I am pretty sure that this post would help others with this same visual studio problem. But apparently this type of question/answer is not welcome at Stack Overflow anymore. – aSkywalker Jan 27 '13 at 15:46
  • 3
    It's easy to take unexplainable down-voting personally. I still do sometimes. I've decided that most downvoting comes from petty individuals that don't speak for the un-countably big collective. – Dave Alperovich Jan 27 '13 at 16:10
  • Copying the 7zip folder to x86 allowed nuget to install the MS Web Optimization on an existing asp.net web site project for me. Thank you for posting your findings. – Mike Q Mar 28 '14 at 17:07
  • Nailed it on the head for me as well. Thank you – Sinaesthetic Apr 22 '14 at 17:41
  • "I tried troubleshooting with the Package Manager in Visual Studio and noticed that it was frozen". Can you explain more about what you did? When I set up my new MVC project, the package manager console doesn't print out anything at all (other than the standard "each package is licensed... blah blah blah"). I assume you had to issue a few commands to find this? – David May 01 '14 at 22:17
2

None of the solutions here worked for me...not on one of my machines, at least.

For one of my machines, jrummell's answer worked perfectly, and I've not had any issues since; on my other machine, I had to follow the steps here: http://patrickdesjardins.com/blog/failed-to-initialize-the-powershell-host in order to stop the error from appearing.

Joe
  • 1,214
  • 3
  • 15
  • 33
0

For future searchers, if aSkywalker's solution isn't working for you, try running VS as administrator. That did it for me (and even more strangely, I haven't seen the error again since... I can't explain that).

David
  • 4,665
  • 4
  • 34
  • 60
0

Found a very easy solution.

The folder where the Solution file is located in needs to have the "read" only property unchecked when doing a right click on the solution folder in Windows Explorer.

Give the folder read / write permissions solve the issue for me :)

Kbdavis07
  • 1,012
  • 13
  • 24
0

I have VS2015 and this steps solved the problem for me

  1. Tools > Extensions and Updates > Updates > Visual Studio Gallery > Nuget Package Manager : Update (this step needs to enter admin password)

  2. restart VS

  3. create new project

Muflix
  • 6,192
  • 17
  • 77
  • 153