簡體   English   中英

Visual Studio 后期構建的 UnauthorizedAccess

[英]UnauthorizedAccess on post build of Visual Studio

我正在嘗試在 Windows 筆記本電腦上工作並在 VB.NET 中定期構建 Visual Studio 后設置post_build.ps1

當我在 powershell 命令上運行腳本時,它沒有任何錯誤。 但是當我通過在 Visual Studio 中構建時,我有這個:

powershell ./_POST_BUILD.ps1 exited with code 1

如果我啟用診斷輸出,我可以通過輸出看到:

1>  AuthorizationManager check failed. (TaskId:39)
1>      + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException (TaskId:39)
1>      + FullyQualifiedErrorId : UnauthorizedAccess (TaskId:39)

我試過的:

  1. 使用Set-ExecutionPolicy Unrestricted -scope LocalMachineSet-ExecutionPolicy Unrestricted -scope CurrentUser Set-ExecutionPolicy Unrestricted -scope LocalMachine Set-ExecutionPolicy Unrestricted -scope CurrentUser
  2. 將 Visual Studio 中的后期構建事件更改為Powershell.exe -ExecutionPolicy Unrestricted -file "$(SolutionDir)bin\\debug\\_POST_BUILD.ps1"
  3. 右鍵單擊取消阻止文件-> 屬性-> 取消阻止
  4. 始終以管理員身份運行 Visual Studio

我不喜歡回答我自己的問題,但我設法解決了它。

出於某種原因,通過右鍵單擊 -> 屬性 -> 取消阻止 -> 應用來取消阻止文件。 我必須在 Powershell 上運行以下內容:

unblock-file --path ./_POST_BUILD.ps1

嘗試將調試輸出添加到您的 powershell 腳本中。 這可以幫助您確定腳本是否正在啟動並在運行時遇到錯誤,或者錯誤是否首先在嘗試運行腳本時出現。

此外,嘗試將 -ExecutionPolicy 開關直接添加到您的 powershell.exe 參數,以確保執行策略不是問題(可能不是,如果您會收到一條明確的消息告訴您)。

確保您的腳本測試運行在與 Visual Studio 相同的用戶帳戶(可能是)和 UAC 提升/未提升狀態下運行(因為您嘗試使用 VS 提升,這可能是一個問題)。

此頁面 ( http://tgnp.me/2011/09/powershell-authorizationmanager-check-failed-resolution/ ) 建議確保 WMI 服務正在運行。

在 Visual Studio Powershell 上復制,運行,然后關閉 VS。 重新打開VS,它起作用了。

Set-ExecutionPolicy –ExecutionPolicy RemoteSigned

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM