Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

nuget - Why does ExecutionPolicy behavior vary across projects in Visual Studio?

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:

File C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEExtensionsMicrosoft CorporationNuGet Package Manager1.7.30402.9028ModulesNuGetprofile.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.

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

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

Get-ExecutionPolicy

PowerShell returns

Restricted

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

Why are existing projects able to use the Package Manager Console while a new one is not?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I experienced the same problem and solved it by:

  • Opening Powershell as an Administrator
  • Entering the following command "Set-ExecutionPolicy RemoteSigned"
  • Restart Visual Studio and the Package Manager Console worked as expected

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

"The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic. Do you want to change the execution policy?"

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...