16

In VS2013, when I try to open the NuGet Package Manager Console, I suddenly get the error:

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

If I run 'Get-ExecutionPolicy -List' in a PowerShell prompt, I get the following:

Scope                 ExecutionPolicy
-----                 ---------------
MachinePolicy         Unrestricted
UserPolicy            Unrestricted
Process               Unrestricted
CurrentUser           RemoteSigned
LocalMachine          Undefined

Not sure it this is correct or not, but on my co-workers PC, the policies are set to:

Scope                 ExecutionPolicy
-----                 ---------------
MachinePolicy         Unrestricted
UserPolicy            Undefined
Process               Unrestricted
CurrentUser           RemoteSigned
LocalMachine          Undefined

Guess the problem is the 'UserPolicy' so I've tried to execute the following command:

Set-ExecutionPolicy Undefined -Scope UserPolicy

which gives me the error-message:

Set-ExecutionPolicy : Cannot set execution policy. Execution policies at the MachinePolicy or UserPolicy scopes must be set through Group Policy.

Not quite sure what to do now. Any help to fix this problem would be greatly appreciated.

SteveC
  • 15,808
  • 23
  • 102
  • 173
smolesen
  • 1,153
  • 3
  • 11
  • 29
  • Others appear to be hitting this problem too since the install of VS2015 and/or VS2013 update 5, both released on July 20th. https://github.com/NuGet/Home/issues/974 – pbar Jul 21 '15 at 13:46

5 Answers5

24

This seems to happen on a workstation that is joined to a domain, and where the domain's group policy includes a specific PowerShell ExecutionPolicy setting.

For now, see the options provided here: https://powershellpanda.wordpress.com/2013/12/01/override-gpo-for-powershell-execution-policy/

Personally, I'm using the temporary fix. Temporarily clearing out the execution policy that was pushed down from my domain. (It will come back of course, but at least I can keep working for now, until a more permanent solution is found.) Here's the regedit script I use:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\PowerShell]
"ExecutionPolicy"=-

See also: https://github.com/NuGet/Home/issues/974#issuecomment-123410075

UPDATE

I think this only started being a problem with Visual Studio 2013 update 5, released yesterday. It affects Visual Studio 2015 (RTM), as well, by the way.

UPDATE 2

A proper nuget fix is now available (for both VS2013 and VS2015), per this post: https://github.com/NuGet/Home/issues/974#issuecomment-124774650

Community
  • 1
  • 1
pbar
  • 451
  • 4
  • 5
  • A quick note here: if your domain sets execution policy in the User as well as Computer group policy (as seems to be the case for the querent here), you'll need to delete the same key from HKCU: as well as/instead of HKLM: – Cerebrate Jul 22 '15 at 13:57
  • Another note, it seems to take a restart after this registry edit for the change to take effect. – Gabby Paolucci Jul 23 '15 at 21:05
  • I followed the link in Update 2 and it solved my problem in VS 2015 – donttellya Jul 26 '15 at 11:50
1

This has happened to me, too, with domain-set PowerShell execution policy (Unrestricted for MachinePolicy). The NuGet version is 2.8.60610.756. The Visual Studio version is Visual Studio 2013 Update 4 (12.0.31101.00; Community Edition). The symptom is that the Package Manager Console is read-only with an error message described in the question by @smolesen, and no prompt is shown.

With the workaround provided by @pbar, my installation also works fine now.

robbie fan
  • 618
  • 1
  • 6
  • 10
0

This has started happening in NuGet 3.0.0.0 which was released with Visual Studio 2015 RTM. Reverting to previous version of NuGet will get rid of the problem.

Calin Pirtea
  • 1,079
  • 7
  • 11
0

It's a problem with VS 2013 update 5. The workaround that works for me is to execute this command in powershell and restart VS.

Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\PowerShell -Name ExecutionPolicy -Value ByPass

I have installed the fix for Nuget tools update and it worked.

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

Siva Kandaraj
  • 824
  • 7
  • 15
0

I tried all of the ideas described above none of them worked.

What worked for me is that I had an invalid character in my directory name

The original directory name ---> Entity Framework 4.1- Expert's Cookbook

The new directory name ---> Entity Framework 4.1 Experts Cookbook

When I removed both the "-" character and the "'" character from the directory name, the problem went away

The problem is with the apostrophe character.