为什么 ExecutionPolicy 行为因 Visual Studio 中的项目而异? [英] Why does ExecutionPolicy behavior vary across projects in Visual Studio?

查看:40
本文介绍了为什么 ExecutionPolicy 行为因 Visual Studio 中的项目而异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在特定 PC 上使用 NuGet 已经有一段时间了.现在,我在 VS2010 中创建了一个新项目(如果重要的话,它是一个使用单页应用程序模板的 MVC 4 Beta 项目).当我选择

I have been using NuGet for quite some time on a particular PC. Now, I created a new project in VS2010 (it's an MVC 4 Beta project using the Single Page App template if that matters). When I select

工具/库包管理器/包管理器控制台

Tools / Library Package Manager / Package Manager Console

控制台窗口打开但显示错误:

The console window opens but displays the error:

文件 C:\Program Files (x86)\Microsoft Visual Studio10.0\Common7\IDE\Extensions\Microsoft Corporation\NuGet Package Manager\1.7.30402.9028\Modules\NuGet\profile.ps1 无法加载因为在此系统上禁用了脚本的执行.请有关详细信息,请参阅get-help about_signing".

File C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft Corporation\NuGet Package Manager\1.7.30402.9028\Modules\NuGet\profile.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

但是,其他项目仍然可以打开和使用包管理器控制台.

However, other projects can still open and use Package Manager Console.

在每种情况下,VS2010 都以相同的用户身份运行.

In each case, VS2010 is running as the same user.

如果我打开命令提示符(使用运行 VS2010 的同一帐户),启动 PowerShell,然后输入命令

If I open a command prompt (using the same account under which VS2010 is running), start PowerShell, and enter the command

获取执行策略

PowerShell 返回

PowerShell returns

受限

我基于 Scott Hanselman 博客 的理解是脚本根本不应该运行如果 ExecutionPolicy 受到限制.

My understanding based on a Scott Hanselman blog is that scripts should not run at all if the ExecutionPolicy is restricted.

为什么现有项目能够使用包管理器控制台而新项目不能?

更新:将 ExecutionPolicy 更改为 AllSigned 重新启动 VS2010 解决了当前的问题,但我的主要问题是为什么其他项目能够绕过已建立的 ExecutionPolicy.VS2010 以管理员身份运行.

Update: Changing the ExecutionPolicy to AllSigned and restarting VS2010 solves the immediate problem, but my main question is why the other projects were able to bypass the established ExecutionPolicy. VS2010 is not running as an administrator.

推荐答案

我遇到了同样的问题并通过以下方式解决了:

I experienced the same problem and solved it by:

  • 以管理员身份打开 Powershell
  • 输入以下命令Set-ExecutionPolicy RemoteSigned"
  • 重新启动 Visual Studio,包管理器控制台按预期工作

需要注意的是,Powershell 会给你一个警告

It is important to note however that Powershell will give you a warning

执行策略有助于保护您免受您不信任的脚本的攻击.更改执行策略可能会使您面临 about_Execution_Policies 帮助主题中描述的安全风险.您要更改执行策略吗??"

并且应该小心启用此功能,并应阅读有关安全风险的帮助主题中的更多信息.

And should be careful of enabling this feature and should read more information in the help topics about the security risks.

这篇关于为什么 ExecutionPolicy 行为因 Visual Studio 中的项目而异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆