asp.net-mvc Nuget 出现此错误“无法加载 ps1,因为正在运行的脚本被禁用”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32692087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Nuget give this error "ps1 cannot be loaded because running scripts is disabled"
提问by Lucian Bumb
I have a new empty MVC 5 project, and I try to install Nuget packages. When I insert in the Nuget Console the command :Update-Package I got the following asnwer:
我有一个新的空 MVC 5 项目,我尝试安装 Nuget 包。当我在 Nuget 控制台中插入命令 :Update-Package 时,我得到了以下答案:
File E:\WebApp\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\tools\uninstall.ps1 cannot be loaded because running scripts is
disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.At line:1 char:3
+ & 'E:\WebApp\packages\Microsoft.CodeDom.Providers.Dot ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
then I start to install some new packages and got again this message:
然后我开始安装一些新软件包并再次收到此消息:
WebApp\packages\Modernizr.2.8.3\tools\install.ps1 cannot be loaded because running scripts is disabled on this system
WebApp\packages\Modernizr.2.8.3\tools\install.ps1 无法加载,因为在此系统上禁用了运行脚本
I saw some posts related with this message, but not related with MVC projects.
我看到了一些与此消息相关的帖子,但与 MVC 项目无关。
My question is:
我的问题是:
Why I get those messages?
为什么我会收到这些消息?
What can I do to fix this issue?
我能做些什么来解决这个问题?
This issue, can appear on the server where my application will run? Some scripts to not run as expected?
这个问题,会出现在我的应用程序将运行的服务器上吗?某些脚本无法按预期运行?
回答by Nikos Tsokos
I guess the specific package you are trying to install needs to run a Powershell script and for some reason, Powershell execution is disabled on your machine. You can search google on "how to enable Powershell" for a complete guide but generally, it goes like this:
我猜您尝试安装的特定软件包需要运行 Powershell 脚本,并且出于某种原因,您的计算机上禁用了 Powershell 执行。您可以在 google 上搜索“如何启用 Powershell”以获取完整指南,但通常是这样的:
- Open up a Powershell command window (just search for Powershell after pressing windows start button)
- Check out current restrictions by typing
Get-ExecutionPolicy - Enable PowerShell by typing
Set-ExecutionPolicy remotesigned
- 打开一个 Powershell 命令窗口(只需在按下 Windows 开始按钮后搜索 Powershell)
- 通过键入检查当前限制
Get-ExecutionPolicy - 通过键入启用 PowerShell
Set-ExecutionPolicy remotesigned
This issue does not affect the server you are planing to install your application on.
此问题不会影响您计划在其上安装应用程序的服务器。
回答by David Sopko
If you encounter this installing NuGet packages from Visual Studio Package Manager Console, run Visual Studio as Administrator.
如果从 Visual Studio 包管理器控制台安装 NuGet 包时遇到此问题,请以管理员身份运行 Visual Studio。
回答by mschr
Translation of the image text would be somewhat: This certificate has been revokedfrom its key store.
图像文本的翻译有点:此证书已从其密钥库中吊销。
Certificate on my init.ps1 has expired - thus RemoteSignedwill not do. For that package version to work, it would need to be set to ByPassor Unrestricted. Personally, i would not recommend doing this...
我的 init.ps1 上的证书已过期 - 因此RemoteSigned不会做。要使该软件包版本正常工作,需要将其设置为ByPass或Unrestricted。就个人而言,我不建议这样做......
-- EDIT -- I went ahead and updated the package and found they have resigned a new cert for v 1.0.2. Issue following in NuGet console for fix:
-- 编辑 -- 我继续更新包,发现他们已经为 v 1.0.2 放弃了新证书。NuGet 控制台中出现以下问题以进行修复:
Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
回答by Robert McCraw
I ran into a similar issue building a project and found that you MAY have to set the execution policy to remoteSigned (as others have mentioned) in BOTH powershell (x86) and powershell (x64). I was running the x64 version as administrator and Get-ExecutionPolicy returned "remoteSigned" but the x86 version hadn't been updated. Just something to try if the above answers don't work for you.
我在构建项目时遇到了类似的问题,发现您可能必须在 powershell (x86) 和 powershell (x64) 中将执行策略设置为 remoteSigned(正如其他人所提到的)。我以管理员身份运行 x64 版本,Get-ExecutionPolicy 返回“remoteSigned”,但 x86 版本尚未更新。如果上述答案对您不起作用,请尝试一些方法。
回答by Pubudu Arosha
open your power-shell as administration and type
以管理员身份打开您的 power-shell 并键入
Get-ExecutionPolicy
Expected result RemoteSigned
预期结果 RemoteSigned
Set-ExecutionPolicy remotesigned
if it does not work, try Powershell run in administrator
如果它不起作用,请尝试以管理员身份运行 Powershell
回答by Kris Craig
In case anybody finds this on Google and this happened to you, I suggest you first try restarting Visual Studio, particularly if the Package Manager Console has worked for you before. In VS 2019, I've noticed that, if I leave it in the background while it's loading, sometimes it'll throw that error.
如果有人在 Google 上发现了这个并且这发生在你身上,我建议你首先尝试重新启动 Visual Studio,特别是如果包管理器控制台以前为你工作过。在 VS 2019 中,我注意到,如果我在加载时将其留在后台,有时会抛出该错误。
For me, restarting Visual Studio and leaving it in the foreground until the Package Manager Console finished initializing solved the issue. Note that running it as administrator was not necessary.
对我来说,重新启动 Visual Studio 并将其留在前台直到包管理器控制台完成初始化解决了这个问题。请注意,不需要以管理员身份运行它。
回答by MD SHAYON
This should work
这应该工作
open your power-shell as administration and type
以管理员身份打开您的 power-shell 并键入
Get-ExecutionPolicy
Expected result RemoteSigned
预期结果 RemoteSigned
Set-ExecutionPolicy remotesigned
Enjoy
享受


