Asp.net-Mvc

Nuget 給出錯誤“ps1 無法載入,因為正在執行的腳本被禁用”

  • September 21, 2015

我有一個新的空 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

然後我開始安裝一些新軟體包並再次收到此消息:

WebApp\packages\Modernizr.2.8.3\tools\install.ps1 無法載入,因為在此系統上禁用了執行腳本

我看到了一些與此消息相關的文章,但與 MVC 項目無關。

我的問題是:

為什麼我會收到這些消息?

我能做些什麼來解決這個問題?

這個問題,會出現在我的應用程序將執行的伺服器上嗎?某些腳本無法按預期執行?

我猜您嘗試安裝的特定軟體包需要執行 Powershell 腳本,並且由於某種原因,您的電腦上禁用了 Powershell 執行。您可以在Google上搜尋“如何啟用 Powershell”以獲取完整指南,但通常情況如下:

  • 打開 Powershell 命令視窗(按下 Windows 開始按鈕後搜尋 Powershell)
  • 通過鍵入查看目前限制Get-ExecutionPolicy
  • 通過鍵入啟用 PowerShellSet-ExecutionPolicy remotesigned

此問題不會影響您計劃在其上安裝應用程序的伺服器。

引用自:https://stackoverflow.com/questions/32692087