安装MvcScaffolding包时出现NuGet执行策略错误

4

我正在使用Visual Web Developer Express 2010,Windows XP,并在项目中使用ASP.NET MVC4 RC。 我已安装NuGet v2.0.30619.9119。

我现在正在尝试通过NuGet Package Manager控制台安装MvcScaffolding包。 我遇到了以下错误:

PM> Install-Package MvcScaffolding
Attempting to resolve dependency 'T4Scaffolding'.
Attempting to resolve dependency 'EntityFramework (≥ 4.1.10311.0)'.
You are downloading EntityFramework from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkId=224682. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'EntityFramework 4.1.10715.0'.
Successfully installed 'T4Scaffolding 1.0.6'.
File Y:\asp\packages\T4Scaffolding.1.0.6\tools\init.ps1 cannot be loaded. The file Y:\asp\packages\T4Scaffolding.1.0.6\tools\init.ps
1 is not digitally signed. The script will not execute on the system. Please see "get-help about_signing" for more details..
At line:1 char:2
+ & <<<<  'Y:\asp\packages\T4Scaffolding.1.0.6\tools\init.ps1' $__rootPath $__toolsPath $__package $__project
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

Successfully installed 'MvcScaffolding 1.0.7'.
File Y:\asp\packages\MvcScaffolding.1.0.7\tools\init.ps1 cannot be loaded. The file Y:\asp\packages\MvcScaffolding.1.0.7\tools\init.
ps1 is not digitally signed. The script will not execute on the system. Please see "get-help about_signing" for more details..
At line:1 char:2
+ & <<<<  'Y:\asp\packages\MvcScaffolding.1.0.7\tools\init.ps1' $__rootPath $__toolsPath $__package $__project
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

Successfully added 'EntityFramework 4.1.10715.0' to MyProject.Web.
Successfully added 'T4Scaffolding 1.0.6' to MyProject.Web.
File Y:\asp\packages\T4Scaffolding.1.0.6\tools\install.ps1 cannot be loaded. The file Y:\asp\packages\T4Scaffolding.1.0.6\tools\inst
all.ps1 is not digitally signed. The script will not execute on the system. Please see "get-help about_signing" for more details..
At line:1 char:2
+ & <<<<  'Y:\asp\packages\T4Scaffolding.1.0.6\tools\install.ps1' $__rootPath $__toolsPath $__package $__project
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

'InstallationDummyFile.txt' already exists. Skipping...
Successfully added 'MvcScaffolding 1.0.7' to MyProject.Web.
File Y:\asp\packages\MvcScaffolding.1.0.7\tools\install.ps1 cannot be loaded. The file Y:\asp\packages\MvcScaffolding.1.0.7\tools\in
stall.ps1 is not digitally signed. The script will not execute on the system. Please see "get-help about_signing" for more details..
At line:1 char:2
+ & <<<<  'Y:\asp\packages\MvcScaffolding.1.0.7\tools\install.ps1' $__rootPath $__toolsPath $__package $__project
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

因为在安装后init脚本没有被执行,所以MvcScaffolding包没有正确安装,scaffold命令无法识别。
我不知道如何处理这些代码签名问题。以下是当前的安全设置:
PM> Get-ExecutionPolicy -List
Scope           ExecutionPolicy
-----           ---------------
MachinePolicy   Undefined
UserPolicy      Undefined
Process         RemoteSigned
CurrentUser     Undefined
LocalMachine    Unrestricted

我可以将进程范围更改为无限制吗?如果可以,如何操作?在NuGet控制台运行Set-ExecutionPolicy不起作用:

PM> Set-ExecutionPolicy Unrestricted
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic. Do you want to change the execution policy?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):Y
Set-ExecutionPolicy : 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 "RemoteSigned". Type "Get-ExecutionPolicy -List" to view your execution policy settings. For more information, please see "Get-Help Set-ExecutionPol
icy."
At line:1 char:20
+ Set-ExecutionPolicy <<<<  Unrestricted
    + CategoryInfo          : PermissionDenied: (:) [Set-ExecutionPolicy], SecurityException
    + FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand

我也尝试过以管理员身份执行所有操作,但这并没有帮助。

任何建议或想法都将不胜感激。

更新

我可以像这样在NuGet中设置进程执行策略:

Set-ExecutionPolicy Unrestricted -Scope Process

但是,当我重新启动Visual Web Developer时,设置被忘记了,我仍然会收到错误提示,因为它仍然尝试执行init.psl文件。

我如何永久更改执行策略?

2个回答

13

好的,我现在已经正确安装了MvcScaffolding。

我必须先绕过NuGet中的所有安全措施:

Set-ExecutionPolicy Bypass -Scope Process

然而,当我重新启动Visual Web Developer时,我仍然会得到与NuGet运行init.pls有关的PowerShell错误。

我发现这是因为我将我的项目存储在网络驱动器上。显然,默认情况下PowerShell不会从网络驱动器执行脚本。

我尝试使用CasPol更改安全设置,但无法使其工作。当我看到其他人也无法让VS与映射驱动器一起工作时,我放弃了:

CAS not working for VS2010 mapped drive

无论如何,我现在只是将我的项目本地化,而MvcScaffolding已经安装并正常运行。


1

您可以为用户范围设置策略,并使用更安全的策略,例如:

Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope CurrentUser

需要所有脚本和配置文件都由可信任的发布者签名,包括您在本地计算机上编写的脚本。 在运行尚未分类为可信任或不受信任的发布者的脚本之前提示您。 例如,安装EntityFramework会要求运行脚本的权限:
Executing script file 'c:\users\user\documents\visual studio 2015\Projects\zzz\packages\EntityFramework.6.1.3\tools\install.ps1'
Do you want to run software from this untrusted publisher?
File C:\users\user\documents\visual studio 2015\Projects\zzz\packages\EntityFramework.6.1.3\tools\install.ps1 is published by CN=Microsoft Corporation, OU=MOPR, O=Microsoft Corporation, L=Redmond, S=Washington, C=US and is not trusted on your system. Only run scripts from trusted publishers.
[V] Never run  [D] Do not run  [R] Run once  [A] Always run  [?] Help (default is "D"):R

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接