无法加载文件,因为在此系统上禁用了脚本的执行

时间:2013-09-30 17:43:44

标签: entity-framework powershell ef-code-first

File C:\Users\Acer\Desktop\Projelerim\BEM_CANLI\BEM\packages\EntityFramework.5.
0.0\tools\init.ps1 cannot be loaded because its execution is blocked by softwar
e restriction policies. For more information, contact your system administrator.
At line:1 char:44
+ $__pc_args=@(); $input|%{$__pc_args+=$_}; & <<<<  'C:\Users\Acer\Desktop\Proj
elerim\BEM_CANLI\BEM\packages\EntityFramework.5.0.0\tools\init.ps1' $__pc_args[
0] $__pc_args[1] $__pc_args[2]; Remove-Variable __pc_args -Scope 0
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

我在包管理器控制台中遇到上述错误。我找到了一些解决方案,但我无法修复它。我尝试了以下

PowerShell says "execution of scripts is disabled on this system."

http://sqlish.com/file-ps1-cannot-be-loaded-because-the-execution-of-scripts-is-disabled-on-this-system-please-see-get-help-about_signing-for-more-details/

我改变了执行政策,

enter image description here

但我总是得到同样的错误。

3 个答案:

答案 0 :(得分:6)

您可能更改了64位PowerShell的执行策略,并且程序包管理器正在运行32位(反之亦然)。

我尝试打开32位控制台(PowerShell(x86))并在那里设置执行策略,因为错误肯定指向那种解决方案。

答案 1 :(得分:1)

确保在更改执行策略后重新启动visual studio,以使更改生效。还要确保使用管理员用户名和密码全局更改执行策略。

答案 2 :(得分:0)

我们今天在使用Visual Studio 2017和Entity Framework 6时遇到了同样的问题,这里提出的解决方案都没有起作用。解决方法是,这是我们发现的临时解决方案,能够在Package Manager控制台中使用Entity Framework命令:

在程序包管理器控制台中执行以下命令

Set-ExecutionPolicy -Scope Process Bypass
Import-Module "your-solution-directory/packages/EntityFramework<your EF version>/EntityFramework.psd1"

实际上,Import-Module命令就是init1.ps1脚本。