I know my question is very similar to this one (Visual Studio Package Installation Error: "Failed to initialize the PowerShell host."). But still the answer that was given there didn't solve my issue.
So like the guy in the link above I have a problem in Visual Studio when I try to create a Web Forms Application or when I want to download and install some Nuget packages (example: AWS DynamoDB sdk) it gives me this error:
failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.
When I did some browsing I came across this command:
Set-ExecutionPolicy Unrestricted
But that didn't help. I still got the error. In the link above someone shares this command:
start-job { Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job
But I don't really know what difference it makes or what it actually does. After trying the first command and doing:
Get-ExecutionPolicy
I got a response that the value is Unrestricted. But in the other command it was still AllSigned. I also tried running Visual Studio as administrator and that didn't help either.
I figured out, that there was a certificate from Microsoft on the Untrusted list, and I needed to delete it, and now it works.
Related
I am creating a Azure build pipeline where I am using a powershell and MSBuild extension to create build. My project has multiple solutions and steps In msbuild. When I am running powershell from system I am able to create build successfully but when I am doing the same thing using Azure pipeline I am getting permission issues as below.
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(4169,5): error MSB3216: Cannot register assembly "C:\Agent\_work\1\s\2021-04-16 17-34-14\BHMessage\RssiStatisticsStorage\bin\Release\RssiStatisticsStorage.dll" - access denied. Please make sure you're running the application as administrator. Access to the registry key 'HKEY_CLASSES_ROOT\FixedNet.Common.TimeUtilities' is denied. [C:\Agent\_work\1\s\2021-04-16 17-34-14\BHMessage\RssiStatisticsStorage\RssiStatisticsStorage.csproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(1620,5): error MSB8011: Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions. [C:\Agent_work\1\s\2021-04-16 17-34-14\BHMessage\FNSKMSCache\FNSKMSCache.vcxproj]
Also i am using VS 2013 and i am able to build solution manually in visual studio. Please don't suggest go to project properties and do this. I have given all access to registry and visual studio is also logged in with admin account, can anyone tell me what is wrong and how to fix this?
You could try to open the agent service, and change the Log On account to an Administrator:
I'm facing this error when I'm trying to create a webApplication Project, a message like below appears:
Package Installation Error
Could not add all required packages to the project. Thw following packages failed to install from 'C:\Program Files (x86)\Michrosoft Web Tools\Packages':
Microsoft.Web.Infrastructure.1.0.0.0: Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.
jQuery.1.10.2: Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.
Modernizr.2.6.2: Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.
Newtonsoft.Json.6.0.4: Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.
Also, after clicking OK it will continue creating the project but in the last step I have this Error message also:
Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.
After all, in Package Manager Console I have this strange message appear:
An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Setting an execution policy to RemoteSigned or Unrestricted should work. It must be changed under an administrator mode via a PowerShell console. Be aware that changes will be applied according to the bit version of the PowerShell console, so 32bit or 64 bit. So if you want to install a package in Visual Studio (32 bit version) which requires a specific policy you should change settings of the policy via PowerShell (x86).
The command in PowerShell (as administrator) to set the policy to unrestricted (as noted by #Gabriel in the comments) is:
start-job { Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job
Having set the policy to unrestricted, you will want to set the policy back to its original after the install is complete.
reinstall -> run the program as administrator -> connect your laptop / desktop to internet for any update or downloadable files.
I use Visual Studio 2019. Nuget packages failed to install and I got a similar error message. Since the error message says
'open the Package Manager Console to initialize the host first'
it can be opened from
View >Other windows >Package Manager Console
for me it was greyed out and the the PMC displayed message
'Registry access denied'
Since new version of Powershells do not replace older existing version and PMC is a powershell console, I believe that execution policy must be set in the PMC.
Starting Visual Studio as administrator solved the problem for me without changing execution policy.
Also see,
https://blog.jsinh.in/nuget-install-update-error-failed-to-initialize-the-powershell-host/
https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio
I have checked extensively for a solution to the below error to no avail.
When opening Package Manager Console in Visual Studio, I receive an error stating that "There was an error in loading the format data file.. Path --> to file" cannot be loaded because its execution is blocked by software restriction policies. For more information contact your administrator.
These are all of the things i've done to correct but failed.
Running Powershell as an Administrator.. I Set-ExecutionPolicy to RemoteSigned and Unrestricted in powershell(x86), powershell ISE (x86) and also both 64bit versions..
Running Powershell as an Administrator.. I Set ExecutionPolicy -scope for process, currentuser and localmachine to RemoteSigned and Unrestricted.
Reinstalled Visual Studio.
Set the ExecutionPolicy in Registry Editor to RemoteSigned and Unrestricted.
But I am still getting the error.. Can someone please help..
Thanks
Let me know if you tried the following:
PowerShell says "execution of scripts is disabled on this system."
http://sqlish.com/file-ps1-cannot-be-loaded-because-the-execution-of-scripts-is-disabled-on-this-system-please-see-get-help-about_signing-for-more-details/
Powershell profile.ps1 cannot be loaded because its operation is blocked by software restriction policies
if all fails do the below:
It's possible that you changed the execution policy for 64-bit
powershell and the package manager is running 32-bit (or vice versa).
I'd try opening 32-bit console (PowerShell (x86)) and setting the
execution policy there, as the error is definitely pointing to that
kind of resolution.
Make sure you restart visual studio after changing execution policy so
that changes can take effect. Also make sure you changed execution
policy globally with administrator username and password.
Source:file cannot be loaded because the execution of scripts is disabled on this system
As a workaround, I found this solution (more details at stackoverflow.com/a/53433786/8358565)
Execute the following commands in the Package Manager Console
Set-ExecutionPolicy -Scope Process Bypass
Import-Module "your-solution-directory/packages/EntityFramework<your EF version>/EntityFramework.psd1"
When I create a new WebAPI project (MVC4) I get the following error.
EntityFramework.5.0.0: Failed to initialize the Powershell host. If your powershell execution policy setting is set to AllSigned, open the package manager console to initialize the host first.
jQuery.1.7.1.1: Failed to initialize the Powershell host. If your powershell execution policy setting is set to AllSigned, open the package manager console to initialize the host first.
After Googling I have found a few answers but nothing that works yet.
Error creating new MVC project - EF and JQuery
This answer seems like it should work for me as my last project was a 7z Command Line app and I might have done something daft with 7zip. But I copy pasted the 7-Zip directory from Program Files to Program Files (86) with no luck.
http://social.msdn.microsoft.com/Forums/en-US/vssetup/thread/c934fed4-e44e-4a06-9e3b-eccb9c8aa8d6
There is an answer here that might work (I haven't tried it) but even if it does work I wouldnt want to do this every time I create a new project.
Is anyone able to help me with this one?
I got around a similar error by running PowerShell as administrator with the command Set-ExecutionPolicy Unrestricted, restarting Visual Studio, and opening the Package Manager Console before what I wanted to do.
Make sure you understand the security implications of doing this first.
http://technet.microsoft.com/en-us/library/ee176961.aspx
Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned - Only scripts signed by a trusted publisher can be run.
RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
Unrestricted - No restrictions; all Windows PowerShell scripts can be run.
I encountered this issue recently, after re-install VS and install the latest VS update 2, things go well. This works for me at least.
I am trying to get a project to build on a machine but i get the following:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(744,5): warning MSB3075: The command "regsvr32 /s "C:\builds\working\\Win32\Debug\projx86.dll"" exited with code 5. Please verify that you have sufficient rights to run this command.
The previous error was converted to a warning because the task was called with ContinueOnError=true.
Build continuing because "ContinueOnError" on the task "Exec" is set to "true".
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(756,5): error MSB8011: Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions.
The user account i am using is an Administrator on the machine so should that not have the highest privileges?
I can go to the startup and right click and run as administrator and that might sort it, but im trying to do an automated build and run of this project, so i cant use that method.
Anyone know how i might fix this?
Solution Explorer ->[YourProject]->Properties->Linker ->General->Per-user Redirection "TRUE"
I found this same issue when working on an C++ ATL project.
In my case, when I added a new ATL class I was missing a line in the resource file (.rc) that adds a resource type "registry" of the new class resource file (.rgs) . This creates the same permission issue stated above.
#LittleFairy answer is probably the best. But you could run Visual Studio as administrator.
Note: You need to explicitly start Visual Studio as administrator. Just the user account having admin rights isn't enough.