When installing an analyzer package into a portable class library, it usually works. But this time I got some unexpected output. At the end, the package _was_ added to packages.config but the analyzer was not installed.
PM> install-package StyleCop.Analyzers -version 1.0.0-alpha-gafdc12e670
Attempting to gather dependencies information for package 'StyleCop.Analyzers.1.0.0-alpha-gafdc12e670' with respect to project targeting '.NETPortable, Version=v4.6, Profile=Profile151'
Attempting to resolve dependencies for package 'StyleCop.Analyzers.1.0.0-alpha-gafdc12e670' with DependencyBehavior 'Lowest'
Resolving actions to install package 'StyleCop.Analyzers.1.0.0-alpha-gafdc12e670'
Resolved actions to install package 'StyleCop.Analyzers.1.0.0-alpha-gafdc12e670'
Adding package 'StyleCop.Analyzers 1.0.0-alpha-gafdc12e670', which only has tools group, to project 'Microsoft.VisualStudio.Threading.Tests.Portable'
Package 'StyleCop.Analyzers 1.0.0-alpha-gafdc12e670' already exists in folder 'C:\Users\andarno\git\Threading\packages'
Added package 'StyleCop.Analyzers 1.0.0-alpha-gafdc12e670' to 'packages.config'
Executing script file 'C:\Users\andarno\git\Threading\packages\StyleCop.Analyzers.1.0.0-alpha-gafdc12e670\tools\install.ps1'
& : File
C:\Users\andarno\git\Threading\packages\StyleCop.Analyzers.1.0.0-alpha-gafdc12e670\tools\install.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
+ & 'C:\Users\andarno\git\Threading\packages\StyleCop.Analyzers.1.0.0-a ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Successfully installed 'StyleCop.Analyzers 1.0.0-alpha-gafdc12e670' to Microsoft.VisualStudio.Threading.Tests.Portable.
PM>
Note in the output how it complains about permissions for running scripts.
VSPro_Platform 22915.00
We don't control permissions or what is in a script. We just hand over the dte object. Either way analyzers are moving away from scripts.
@deepakaravindr did we change threading when we start the powershell scripts leading to a potential race condition?
@AArnott can we have access to the machine where this happens? Does it still repro? If it does, can you grab the latest nuget vsix and verify with it?
Assigning to @feiling to take a look
@AArnott could you tell me the NuGet version installed on your VS? The version number that you get thru Tools -> Extensions and Updates. Recently there was a fix about the powershell execution policy so that no matter what your current policy is, NuGet always uses ByPass when executing powershell scripts in packages. Also, as Yishai suggested, please try the latest build and see if it still repros.
Sorry I haven't replied for a while. Given that you've fixed a bug in this area and I was on an old drop, I'll close as not repro. I'll reactivate if I see it again on a current drop.
It repros on D14Rel 23103.00
PM> Install-Package VSSDK.NavigateTo -Pre
Attempting to gather dependencies information for package 'VSSDK.NavigateTo.14.0.4-preview' with respect to project 'Microsoft.VisualStudio.SLNX', targeting '.NETFramework,Version=v4.6'
Attempting to resolve dependencies for package 'VSSDK.NavigateTo.14.0.4-preview' with DependencyBehavior 'Lowest'
Resolving actions to install package 'VSSDK.NavigateTo.14.0.4-preview'
Resolved actions to install package 'VSSDK.NavigateTo.14.0.4-preview'
Adding package 'VSSDK.NavigateTo.14.0.4-preview' to folder 'C:\personal\git\SLNX\packages'
Added package 'VSSDK.NavigateTo.14.0.4-preview' to folder 'C:\personal\git\SLNX\packages'
Added package 'VSSDK.NavigateTo.14.0.4-preview' to 'packages.config'
Executing script file 'C:\personal\git\SLNX\packages\VSSDK.NavigateTo.14.0.4-preview\tools\install.ps1'
& : File C:\personal\git\SLNX\packages\VSSDK.NavigateTo.14.0.4-preview\tools\install.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
- & 'C:\personal\git\SLNX\packages\VSSDK.NavigateTo.14.0.4-preview\tools\install.p ...
~~~~~~~~~~~~~~~~
- CategoryInfo : SecurityError: (:) [], PSSecurityException
- FullyQualifiedErrorId : UnauthorizedAccess
Successfully installed 'VSSDK.NavigateTo 14.0.4-preview' to Microsoft.VisualStudio.SLNX
PM>
We need a clear repro, start from scratch if you can.
This was a fresh VM, so it was from scratch. I think it was Windows 10 as well.
I tried creating two VMs to repro this, and couldn't. So once again, it appears that this is a randomly occurring bug. :(
Please reopen if you continue to see this issue.
This issue should be improved by a recent PS fix in 3.1.1
NuGet/NuGet.visualstudioextension@71cb4ca6b3509c8dfd16887a8471d2e342887211
For the record, I saw this randomly repro on a machine that hadn't changed for several days. And it immediately disappeared after that.
I saw this issue yesterday on a Windows 10 VM. As part of testing, I had created many MVC projects without incident. Then I created a new MVC project and noticed various problems. It became clear that none of the powershell scripts ran when installing the NuGet packages. The output window showing output from Package Manager is attached.
NuGetPowerShellErrors.txt
I should add the NuGet Package Manager for Visual Studio version is 3.3.0.167
Just to add further observation on this issue:
I currently have a Windows 10 VM with VS 2015 Update 1 (and NuGet Package Manager for Visual Studio version is 3.3.0.167) installed.
I started seeing this issue yesterday when attempting to create an MVC project using a custom project template that we use. I left this copy of Visual Studio open. I seem to keep seeing the issue occurring constantly in this copy of VS 2015. For example, I removed one NuGet package which is known to have an install script and attempted to reinstall it and got the same "install.ps1 cannot be loaded because running scripts is disabled on this system" message. I also created another MVC project in the same solution and saw the same errors.
Meanwhile, I started a second copy of VS 2015. I created a new MVC project in a new solution using the same template without getting the errors. I also performed the same uninstall/reinstall of the same NuGet package without error.
So, in summary, I have two copies of VS 2015 running at the same time on the same machine, and one gets the errors and the other does not.
Not sure if that helps.
I am seeing it randomly pop up still as well.
I wanted to add that we have been seeing this with init.ps1, install.ps1, and uninstall.ps1 somewhat sporadically. It seems the execution policy sometimes gets demoted but it isn't clear when it happens.
Version info:
NuGet Package Manager for Visual Studio 2015 Version 3.4.4.1321
Here is the error with the package and project details scrubbed out:
`Executing script file '
& : File
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:45
The workaround has been to close/reopen Visual Studio, and uninstall/reinstall the package. Any updates on if this will be fixed soon?
close it, if this still repros on VS 2017, feel free to reopen it.
Most helpful comment
I wanted to add that we have been seeing this with init.ps1, install.ps1, and uninstall.ps1 somewhat sporadically. It seems the execution policy sometimes gets demoted but it isn't clear when it happens.
Version info:
NuGet Package Manager for Visual Studio 2015 Version 3.4.4.1321
Here is the error with the package and project details scrubbed out:
`Executing script file '\tools\install.ps1'...\tools\install.ps1 cannot be
& : File
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:45
~~~~~~~~~~~~~Successfully installed '
The workaround has been to close/reopen Visual Studio, and uninstall/reinstall the package. Any updates on if this will be fixed soon?