Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet Package Manager Console (PMC) policy settings

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.

like image 713
smolesen Avatar asked Jul 21 '15 10:07

smolesen


People also ask

How do I open PMC in Visual Studio?

To open the console in Visual Studio, go to the main menu and select Tools > NuGet Package Manager > Package Manager Console command.

How do I use package manager console?

Open your project or solution in Visual Studio, and then open the Package Manager Console in Visual Studio by navigating to Tools > NuGet Package Manager > Package Manager Console. By default, console commands operate against a specific package source and project as set in the control at the top of the window.

How do I open the NuGet Manager console?

Opening the console and console controls Open the console in Visual Studio using the Tools > NuGet Package Manager > Package Manager Console command. The console is a Visual Studio window that can be arranged and positioned however you like (see Customize window layouts in Visual Studio).


2 Answers

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

like image 127
pbar Avatar answered Oct 13 '22 13:10

pbar


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.

like image 22
robbie fan Avatar answered Oct 13 '22 15:10

robbie fan