I am trying to work on a Windows laptop and setup a post_build.ps1
after the regular build of Visual Studio in VB.NET
When I run the script on powershell command, it doesn't have any error. But when I do it through Build in Visual Studio, I have this:
powershell ./_POST_BUILD.ps1 exited with code 1
If I enable the diagnostic output, I can see through the output this:
1> AuthorizationManager check failed. (TaskId:39)
1> + CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException (TaskId:39)
1> + FullyQualifiedErrorId : UnauthorizedAccess (TaskId:39)
What I tried:
Set-ExecutionPolicy Unrestricted -scope LocalMachine
and Set-ExecutionPolicy Unrestricted -scope CurrentUser
Powershell.exe -ExecutionPolicy Unrestricted -file "$(SolutionDir)bin\\debug\\_POST_BUILD.ps1"
I don't like to answer my own questions, but I managed to fix it.
For some reason, unblocking the file with Right Click -> Properties -> Unblock -> Apply. I had to run on Powershell the following:
unblock-file --path ./_POST_BUILD.ps1
Try adding debug output to your powershell script. This can help you determine if the script is even starting and hitting an error while it runs, or if the error is in trying to run the script in the first place.
Also, try adding the -ExecutionPolicy switch directly to your powershell.exe arguments to be sure that the execution policy isn't an issue (probably not, if it was you'd get an explicit message telling you that).
Make sure your test run of the script is running under the same user account (probably is) and UAC elevated/not elevated state as Visual Studio (since you tried using VS elevated that is unlkely a problem).
This page ( http://tgnp.me/2011/09/powershell-authorizationmanager-check-failed-resolution/ ) recommends ensuring the WMI service is running.
Copy on Visual Studio Powershell, run and after close VS. Reopen VS, it worked.
Set-ExecutionPolicy –ExecutionPolicy RemoteSigned
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.