简体   繁体   English

Visual Studio 后期构建的 UnauthorizedAccess

[英]UnauthorizedAccess on post build of Visual Studio

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我正在尝试在 Windows 笔记本电脑上工作并在 VB.NET 中定期构建 Visual Studio 后设置post_build.ps1

When I run the script on powershell command, it doesn't have any error.当我在 powershell 命令上运行脚本时,它没有任何错误。 But when I do it through Build in Visual Studio, I have this:但是当我通过在 Visual Studio 中构建时,我有这个:

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:我试过的:

  1. Set the policies to unrestricted with Set-ExecutionPolicy Unrestricted -scope LocalMachine and Set-ExecutionPolicy Unrestricted -scope CurrentUser使用Set-ExecutionPolicy Unrestricted -scope LocalMachineSet-ExecutionPolicy Unrestricted -scope CurrentUser Set-ExecutionPolicy Unrestricted -scope LocalMachine Set-ExecutionPolicy Unrestricted -scope CurrentUser
  2. Change the post build event in Visual Studio to Powershell.exe -ExecutionPolicy Unrestricted -file "$(SolutionDir)bin\\debug\\_POST_BUILD.ps1"将 Visual Studio 中的后期构建事件更改为Powershell.exe -ExecutionPolicy Unrestricted -file "$(SolutionDir)bin\\debug\\_POST_BUILD.ps1"
  3. Unblock file with right click -> properties -> unblock右键单击取消阻止文件-> 属性-> 取消阻止
  4. Run Visual Studio as administrator always始终以管理员身份运行 Visual Studio

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:我必须在 Powershell 上运行以下内容:

unblock-file --path ./_POST_BUILD.ps1

Try adding debug output to your powershell script.尝试将调试输出添加到您的 powershell 脚本中。 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).此外,尝试将 -ExecutionPolicy 开关直接添加到您的 powershell.exe 参数,以确保执行策略不是问题(可能不是,如果您会收到一条明确的消息告诉您)。

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).确保您的脚本测试运行在与 Visual Studio 相同的用户帐户(可能是)和 UAC 提升/未提升状态下运行(因为您尝试使用 VS 提升,这可能是一个问题)。

This page ( http://tgnp.me/2011/09/powershell-authorizationmanager-check-failed-resolution/ ) recommends ensuring the WMI service is running.此页面 ( http://tgnp.me/2011/09/powershell-authorizationmanager-check-failed-resolution/ ) 建议确保 WMI 服务正在运行。

Copy on Visual Studio Powershell, run and after close VS.在 Visual Studio Powershell 上复制,运行,然后关闭 VS。 Reopen VS, it worked.重新打开VS,它起作用了。

Set-ExecutionPolicy –ExecutionPolicy RemoteSigned

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM