Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget gives the error "ps1 cannot be loaded because running scripts is disabled"

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:

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

I saw some posts related with this message, but not related with MVC projects.

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?

like image 504
Lucian Bumb Avatar asked Sep 21 '15 09:09

Lucian Bumb


3 Answers

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:

  • 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

This issue does not affect the server you are planing to install your application on.

like image 128
Nikos Tsokos Avatar answered Oct 17 '22 18:10

Nikos Tsokos


If you encounter this installing NuGet packages from Visual Studio Package Manager Console, run Visual Studio as Administrator.

like image 30
David Sopko Avatar answered Oct 17 '22 17:10

David Sopko


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.

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.

like image 7
Kris Craig Avatar answered Oct 17 '22 18:10

Kris Craig