Unauthorized access to Visual Studio post-build
I am trying to work on a Windows laptop and tweak post_build.ps1
after a normal Visual Studio build in VB.NET
When I run the script on powershell command, it has no errors. But when I do it through Build in Visual Studio I have this:
powershell ./_POST_BUILD.ps1 exited with code 1
If I turn on the diagnostic output, I can see through the output:
1> AuthorizationManager check failed. (TaskId:39)
1> + CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException (TaskId:39)
1> + FullyQualifiedErrorId : UnauthorizedAccess (TaskId:39)
What I have tried:
- Install policies without restriction using
Set-ExecutionPolicy Unrestricted -scope LocalMachine
andSet-ExecutionPolicy Unrestricted -scope CurrentUser
- Change the post build event in Visual Studio to
Powershell.exe -ExecutionPolicy Unrestricted -file "$(SolutionDir)bin\debug\_POST_BUILD.ps1"
- Unlock file with right click -> properties -> unlock
- Always run Visual Studio as administrator
source to share
Try adding debug output to your powershell script. This can help you determine if the script is actually running and hitting an error while it runs, or if the error is trying to run the script in the first place.
Also, try adding the -ExecutionPolicy switch directly to the arguments to powershell.exe to make sure the execution policy is not the problem (probably not if you got an explicit message telling you this).
Make sure your test run script is running under the same user account (there probably is) and the UAC is elevated / not elevated as Visual Studio (since you were trying to use VS elevated, which is an annoying issue).
This page ( http://tgnp.me/2011/09/powershell-authorizationmanager-check-failed-resolution/ ) recommends ensuring that the WMI service starts.
source to share