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

34

178

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' already installed.

Adding 'Newtonsoft.Json 6.0.3' to Tournaments.Notifications.

Successfully added 'Newtonsoft.Json 6.0.3' to Tournaments.Notifications.

Executing script file 'F:\My Webs\BasketballTournaments\MainBranch\packages\Newtonsoft.Json.6.0.3\tools\install.ps1'.

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.

Package Manager Console

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.

Pifer answered 29/4, 2014 at 1:26 Comment(4)
Hi Mike. I have the exact same issue. Have you managed to solve the problem and you have a working nuget package manager?Buttercup
I have the same problem. I have already set the execution policy of Powershell to be Unrestricted, but it doesn't help. I install the package in Package Manager Console no problem.Sherris
Just experienced tha same issue. This solution has helped me: #10457539Floriculture
I had the same error on Windows 10. I had to enable Powershell 2.0 from the "programs and features" > "Turn Windows Features on or off" and then all worked fine after restarting visual studio.Cultured
T
197

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.

Turne answered 15/5, 2014 at 8:15 Comment(6)
Worked for me. When you change the ExecutionPolicy in PowerShell on 64 bit systems it will only change it for the 64 bits version of PowerShell. But VS is a 32 bit process and the "Package Manager Console" is a 32 bit process too. To fix this you can execute start-job { Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job in a 64 bit PowerShell console.Bootstrap
You need to restart Visual Studio afterwards.Breger
Works fine. It's a pity the package itself suggests a solution that doesn't work. And don't forget to turn on the original policy afterwards.Mice
Closed the VS 2013, run as admin, started working fine...wieredRoulade
I had this issue in VS2015 and simply updating the NuGet paackage manager resolved the issueSmukler
IMO @Smukler comment and the other answers similar to this should probably be tried first before doing PowerShell. They really f'ed the initial release of Nuget Package Manager for VS 2015Brokendown
J
56

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.

Joellenjoelly answered 16/6, 2014 at 7:33 Comment(0)
S
53

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

Superfuse answered 26/4, 2015 at 11:52 Comment(5)
Thank you! Only when I did the windows powershell command the way you stated did it work. Thanks so much!Coons
This worked for following environment: windows xp, visual studio 2010 Web developer express. I closed the visual studio. Downloaded microsoft.com/en-us/download/confirmation.aspx?id=16818 Powershell. Installed Powershell. Run powershell and executed start-job { Set-ExecutionPolicy RemoteSigned } -RunAs32 | wait-job | Receive-Job . Started visual studio and used nuget. It worked.Perceptible
@muflix: not possible in that case, at least I wouldn't know how. In the end it's a security issue and thus left to administratorsSuperfuse
do we need to close the doors after? how?Butyl
closing it would leave nuget inoperable since it needs to execute scripts during installation of packesSuperfuse
V
26

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

Vassell answered 21/6, 2014 at 8:16 Comment(5)
You should ask a new question.Pardner
I didn't think this warranted a new question as it directly relates to the issue raised. I reworded the post so as to not sound so much like a new question but the musings of a disgruntled developer.Vassell
@Vassell The end of this answer (post-edit) should be either a comment or a question.Breger
Thanks for your input Danny, I was hoping to share my experience and a possible work-around for those people that didn't want or couldn't change the security settings. The answer does read better now.Vassell
Get-Package -Filter PartOfPackageName to search through the installed package, Install-Package PackageName -Version 7.0.1 to install specific version of the package. Don't forget to select Default Project in the top of the Package Manager ConsoleRhoads
G
25

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.

Grampus answered 27/8, 2015 at 13:44 Comment(3)
Uninstalling and reinstalling was the only thing that helped indeed. This issue is also described here: github.com/NuGet/Home/issues/974Everetteverette
I reinstalled the NuGet VSIX package without uninstalling it first, which resolved the issue.Owenowena
+1 marketplace.visualstudio.com/… for VS2015Waite
G
18

Running the Visual Studio as Administrator worked for me.

Gruelling answered 8/6, 2015 at 7:22 Comment(2)
Ditto, though people should remember to close VS once your package is installed, and reopen under regular permissions.Glandule
Totally agree @LiamLavertyGruelling
J
7

I updated the Nuget package manager and that fixed it for me.

Jugurtha answered 7/9, 2015 at 15:55 Comment(0)
I
7

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

Induline answered 8/9, 2015 at 9:5 Comment(1)
How? It complains it's being used by another processPopsicle
I
6

This started happening with 6.0.4 recently for me, I don't think this is a very good solution but here is what helped me. Close Visual Studio

  1. Open a Windows PowerShell prompt as Administrator (very important) and run the following command:Set-ExecutionPolicy Bypass
  2. Open Visual Studio, open your solution and use Nuget to install JSON.Net (or whatever package included it as a dependency).
  3. Once everything is working, I recommend setting the powershell execution policy back to restricted with the following command: Set-ExecutionPolicy Restricted
Incommunicado answered 27/1, 2015 at 17:25 Comment(0)
B
6

I had the same problem after upgrading to Windows 10.

This worked for me

  1. Close Visual Studio
  2. Run Powershell as admin
  3. Run Set-ExecutionPolicy Unrestricted
  4. Run Visual studio as admin
  5. Clean the project and add the nuget package

If it still doesn't work try editing 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

Add the following

    <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>
Billhead answered 5/10, 2015 at 2:53 Comment(2)
Adding Powershell dependencies to the devenv.exe.config is the only fix that worked for me both in VS2013 and VS2015. VS2013: C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\12.0 VS2015: C:\Users\<username>\AppData\Local\Microsoft\VisualStudio\14.0 What didn't work for me was changing execution policy, changing the execution policy in the registry, reinstalling package manager, repairing visual studio, restarting visual studio, restarting windows.Angst
Wooooow. All the other Methods did not solve it for me in VS 2015. Only adding the dependencies to devenv.exe.config helped. After this I also found #12638789. Thank you so so much!!!Sullyprudhomme
F
6

If the above answers dint work for you -

  1. Open Run - windows + R
  2. Open registry editor - type regedit.exe
  3. Open - HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\PowerShell
  4. In the right pane - Modify "ExecutionPolicy" and keep its "Value Data" as blank.
  5. Restart your visual studio, Now your Powershell can initialize properly.
Fraternize answered 2/11, 2017 at 4:56 Comment(0)
D
4

This Nuget fix worked for me:

https://github.com/NuGet/Home/issues/974#issuecomment-124774650

Deannedeans answered 15/9, 2015 at 15:14 Comment(0)
R
4

By default my Windows 10 64-bit only had Powershell version 1.0 enabled. I changed the control panel/Programs/Programs and features/Turn Windows features On Off.

Make sure the Windows Powershell 2.0 engine is enabled.

Restart VS2015 in non-administrator mode and with all packages installed correctly.

Radiophone answered 30/10, 2015 at 3:4 Comment(1)
I also have Windows 10 64-bit and I needed to enable Windows Powershell 2.0 engine to get the Package Manager Console to work. It is odd that this issue has been around for some time and Microsoft has not enabled the Powershell 2.0 engine as part of the Visual Studio 2017 install process.Chyou
P
4

I had the same problem with vs2013 and changing execution policy did not fix it. The only working solution I found was uninstalling Nuget from VS and installing it again. Steps are here: https://mcmap.net/q/144142/-nuget-crash-in-visual-studio-2015

Ppm answered 11/11, 2015 at 9:16 Comment(0)
C
4

Close all the visual studio instances and try again. It worked for me :)

Chuipek answered 21/12, 2015 at 4:19 Comment(0)
F
3

All I needed to do was restart Visual Studio, open the NuGet Package Manager Console, and then using the Manage NuGet Packages dialog worked.

Faefaeces answered 28/5, 2015 at 14:52 Comment(0)
A
3

After trying various suggested fixes, it was finally solved by updating the NuGet Package Manager extension in Visual Studio.

This is done under Tools -> Extensions And Updates, then in the Extensions and Updates dialog Updated -> Visual Studio Gallery. A restart of Visual Studio may be required.

Anecdotage answered 26/10, 2015 at 8:20 Comment(0)
T
2

Had the same problem and this solved it for me (Powershell as admin):

Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\PowerShell -Name ExecutionPolicy -Value ByPass 
Tenon answered 8/10, 2015 at 7:52 Comment(0)
E
2

If you use VS 2013 Update 5, you should manually install an update 2.8.7 for NuGet Packet Manager.

The bug report has more details.

Enlil answered 12/11, 2015 at 14:57 Comment(0)
L
2

VS2015: Updated the NuGet and worked.

Lamoreaux answered 14/12, 2015 at 6:4 Comment(1)
Same here. Was using VS2015 and just updated the Nuget Package Manager and it worked.Myronmyrrh
B
2

What did the trick for me was to re-install NuGet Package Manager by using the link below:

VS 2013: https://github.com/NuGet/Home/releases/download/2.8.7/NuGet.Tools.vsix

VS 2015: https://github.com/NuGet/Home/releases/download/3.1.1/NuGet.Tools.vsix

Bartell answered 14/3, 2016 at 19:58 Comment(0)
B
2

If none of the above helps, see if you can update Visual Studio.

I Had the same issue with Visual Studio 2017 Community when I tried to install Newtonsoft.Json. The ExecutionPolicy change didn't help (I tried using both PowerShell and Registry Editor). I also tried to uninstall and install NuGet.

After running VS2017 setup file, it asked for update of Visual Studio. All the problems disappeared after the update.

Beget answered 28/3, 2017 at 17:34 Comment(0)
J
1

For me setting the execution policy to Unrestricted did not work. I had to repair the vs2013 installation by going into Control Panel. Repairing the installation worked for me.

Jacobean answered 22/6, 2014 at 1:15 Comment(0)
B
1

after trying all the suggested solution nothing worked on VS 2015 update 2

deleting the package folder from the solution folder and restoring it from visual studio worked for me

Boland answered 18/4, 2016 at 2:5 Comment(0)
B
1

I had a similar problem. I have fixed it by turning "Windows PowerShell 2.0" feature on in "Turn Windows features on or off". Note that this feature is turned on by default, I manually turned it off few days ago.

I'm working on Windows 10 Pro 64bit and same problem was with Visual Studio 2015 and 2017 (32bit and 64bit app)

Boredom answered 9/7, 2017 at 9:37 Comment(0)
P
0

Download and Install Administrative Templates for Windows PowerShell

Next:  Powershell x86 from As Administrator

Run:   Get-ExecutionPolicy -List  , and see if you have RemoteSigned etc..

1. 5 different scopes  Set-ExecutionPolicy "RemoteSigned" -Scope Process -Confirm:$false

2. Machine and User Policy you have to set through the Group Policy Administration Template in 2 areas.

UPDATE - EDIT:

Set ALL of them to  "Undefined" and ONLY the LocalMachine to "Restricted" 

This is what fixed might after I had given my powershell more permissions not knowing that it would mess up visual studio 2013 and 2015

Pianist answered 24/7, 2015 at 23:35 Comment(0)
R
0

This issue is not always related to the PowerShell Execution Policy. My machine is configured as "Unrestricted" for both PowerShell x64 and x86, but I still get this error message from times to times in Visual Studio 2013.

When I try to open the Package Manager Console:

Windows PowerShell updated your execution policy successfully, but the setting is overridden by a policy defined at a more specific scope. Due to the override, your shell will retain its current effective execution policy of Unrestricted. Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more information please see "Get-Help Set-ExecutionPolicy".

This is not a valid error message.

Rebooting Visual Studio does not always resolve the problem.

Running the process as an admin never resolves the problem.

Like Declan, the latest update of the Package Manager plugin fixed the issue: 2.8.60723.765

Rascally answered 9/9, 2015 at 15:31 Comment(0)
U
0

Set the execution policy to Bypass instead of Unrestricted or RemoteSigned; this tutorial gives fuller instructions. Also, if you are having trouble using PowerShell to change the policy then the author shows you how to change it in Regedit.

Uyekawa answered 6/11, 2015 at 15:30 Comment(1)
Unrestricted should work just as well--it merely warns you when you may be doing something unsafe, where Bypass would just go ahead and run the command.Scoggins
S
0

There are an awful lot of stabs in the dark here, so I'll add my own.

In my case, I also got a message that there was a missing lock file, and a recommendation to run dnu restore in the package manager console. I did so, restarted VS, and everything is now working.

Scoggins answered 28/1, 2016 at 11:33 Comment(0)
B
0

What worked for me is:

  1. Set Execution policy to Unrestricted.
  2. Find-Module ISEModuleBrowserAddon | Install-Module
  3. Import-Module ISEModuleBrowserAddon
  4. Find-Module ISEScriptAnalyzerAddOn | Install-Module
  5. Import-Module ISEScriptAnalyzerAddOn
  6. Import-Module ScriptBrowser
  7. In ISE, you need Enable-ScriptBrowser

And you have Module, Script, and Analyser in your ISE.

Run in Win 10 Pro, x64 Console Host 5.0.10586.122

Good Luck!

Beaune answered 27/4, 2016 at 2:29 Comment(0)
A
0

Apparently there is a Powershell bug in Windows 10 version 1511.

None of the fixes listed here worked for me. (or only worked temporarily)

I fixed it (both in VS2013 and VS2015) by installing version 1607. It can be downloaded here: Windows 10 Anniversary Update.

Nuget issue: https://github.com/NuGet/Home/issues/3352

Angst answered 25/8, 2016 at 12:14 Comment(0)
B
0

My problem solved, because in this time .Net Core not supported EF 6.2.0.

change project from Core and EF installed successfully.

Backup answered 21/11, 2017 at 19:28 Comment(0)
W
0

You need to open PM console( Tools > Nuget Package Manager > Package Manager Console), it will prompt you if you want to run nuget manager as untrusted , type 'A' and click enter that will resolve the issue.

Wilding answered 20/12, 2017 at 7:39 Comment(0)
A
0

I run this command on powershell (run as admin) and it solve my issue.

reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\PowerShell /v ExecutionPolicy /f
Auvil answered 5/4, 2019 at 20:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.