Ryan Duffing
Ryan Duffing

Reputation: 674

Entity Framework PowerShell script cannot be loaded by Visual Studio because its operation is blocked by software restriction policies

When I load Package Manager Console within Visual Studio 2017 v15.9.6 in a project that uses Entity Framework I receive the following error:

\packages\EntityFramework.6.2.0\tools\init.ps1 cannot be loaded because its operation is blocked by software restriction policies, such as those created by using Group Policy. At line:1 char:45 + ... rgs+=$_}; & 'C:\Bitbucket\project-path\packages\EntityFramework.6.2. ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess

This prevents me from running commands specific to Entity Framework like "Update-Database" or "Add-Migration".

Here are things I have tried:

  1. Reinstall Visual Studio
  2. In Group Policy Editor, for both Computer Configuration and User Configuration, I have enabled the setting "Turn on Script Execution" that is located at "Administrative Templates\Windows Components\Windows PowerShell". The setting for both configurations has the "Execution Policy" set to "Allow all scripts". screenshot of script execution setting

  3. I've tried locally in the Package Manager Console setting the "Process" scope to both "Bypass" and "Unrestricted", and then manually loading the Entity Framework init.ps1 script. I receive the same error.

  4. I've also tried modifying registry keys for PowerShell to set the ExecutionPolicy to "Unrestricted" in a few places. Those places are at:
    • HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell
    • HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps120
    • HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps140
  5. I've restarted multiple times in between doing all of the above.

When I run the command "Get-ExecutionPolicy -List", here are my results"

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

After all of the above I expected to be able to just load Visual Studio as normal, launch Package Manager Console, and not receive any errors when it tries to run the Entity Framework init.ps1 script. I must be missing something or doing something incorrectly. What do I need to do to get Visual Studio to work as expected?

Some more information is that this is a computer joined to a company domain, but no other developers have this issue. There isn't a group policy set by an administrator that is trickling down preventing me from running scripts.

Upvotes: 5

Views: 4426

Answers (3)

Coding Knowledge
Coding Knowledge

Reputation: 11

Remove file inside

control=>internet option => content => certificates =>Untrusted publishers

then problem will solve

Upvotes: 1

Rafael Augusto
Rafael Augusto

Reputation: 415

The error may be occurring because of an invalid certificate from Microsoft. Check in Control Panel => Internet Options => Content => Certificates on the Untrusted Publishers tab. Remove Microsoft Corporation from this list.

Sounds bizarre but it worked for me.

Tks https://github.com/NuGet/Home/issues/7158

Upvotes: 14

Hakim
Hakim

Reputation: 482

Try downgrading to EF 6.1.2.

I ran into the same problem as you. I tried changing the Group Execution Policies which in my case didn't work, because of some restriction on my local machine (may be set by my school admin). In another project I used 6.1.2 where things like migration was no problem.

Upvotes: 0

Related Questions