36

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?

David Sopko
  • 5,263
  • 2
  • 38
  • 42
Lucian Bumb
  • 2,821
  • 5
  • 26
  • 39

8 Answers8

55

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.

Community
  • 1
  • 1
Nikos Tsokos
  • 3,226
  • 2
  • 34
  • 41
9

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

David Sopko
  • 5,263
  • 2
  • 38
  • 42
  • 1
    If you run as Administrator and type `Get-ExecutionPolicy` in Package Manager Console, you get `RemoteSigned`. If you just run Visual Studio not as Administrator, you get `Restricted` for `Get-ExecutionPolicy`. And because it is Restricted, you cannot run scripts. Re: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-6&viewFallbackFrom=powershell-Microsoft.PowerShell.Core#restricted – Just a HK developer Jul 17 '18 at 02:57
8

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.

Kris Craig
  • 558
  • 1
  • 7
  • 19
5

enter image description here

Translation of the image text would be somewhat: This certificate has been revoked from its key store.

Certificate on my init.ps1 has expired - thus RemoteSigned will not do. For that package version to work, it would need to be set to ByPass or Unrestricted. Personally, i would not recommend doing this...

-- 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:

Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
mschr
  • 8,531
  • 3
  • 21
  • 35
  • I got the above error on Windows 7 Pro, following Entrodus advice I manage to fix the issue. Now I am using Windows 10 and I had no similar issue. – Lucian Bumb Oct 23 '16 at 02:42
  • Updating the package solved my issue on VS2015 at Win10 as well. Thanks. – Paul Meems Oct 25 '16 at 10:45
  • Was getting this error on VS2017 in Windows 10, running VS as admin, execution policy Unrestricted... this fixed the problem. Thanks! – SWalters Mar 04 '18 at 14:30
2

open your power-shell as administration and type

Get-ExecutionPolicy

Expected result RemoteSigned

Set-ExecutionPolicy remotesigned

if it does not work, try Powershell run in administrator

Arosha
  • 511
  • 1
  • 7
  • 19
1

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.

Robert McCraw
  • 663
  • 3
  • 8
  • 22
0

This should work

open your power-shell as administration and type

Get-ExecutionPolicy

Expected result RemoteSigned

Set-ExecutionPolicy remotesigned

Enjoy

MD SHAYON
  • 7,001
  • 45
  • 38
0

A quick to fix this error when using Package Manager Console without VS restart and/or running as Admin is to remove the restriction for current user:

Set-ExecutionPolicy remotesigned -scope CurrentUser
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164