簡體   English   中英

從 Azure DevOps 管道啟動 Developer PowerShell for VS 2019

[英]Start Developer PowerShell for VS 2019 from Azure DevOps pipeline

我們已經配置了一個 Windows 虛擬機並在那里部署了一個代理來構建我們的代碼和運行腳本。

在我們的 VM 中,我們有兩種不同風格的 PowerShell 命令提示符:

  1. Windows PowerShell
  2. VS 2019 的開發人員 PowerShell。

我們如何從管道 YAML 腳本啟動“Developer PowerShell for VS 2019”並在那里執行我們簽出的.ps1文件?

不過,有幾種類型的 PowerShell 任務可以從管道啟動,但不確定其中哪一種可以達到目的。 它們是:

  1. Azure PowerShell
  2. 電源外殼
  3. 目標機器上的 PowerShell
  4. 服務結構 PowerShell。

以上哪項代表“VS 2019 的開發人員 PowerShell”?

這種特殊風格的 PowerShell 背后的原因是:

  1. 需要一些 .NET Framework 工具 (CorFlags.exe),這些工具只能在“VS 2019 的 Developer PowerShell”中訪問,而不能在另一個中訪問。

VS 2019 的 Developer PowerShell是一個導入了模塊的常規 PowerShell,您可以通過這種方式確切地看到:

  • 轉到開始菜單並搜索Developer PowerShell for VS 2019
  • 右鍵單擊它並打開文件位置- 你會得到這個:

在此處輸入圖像描述

  • 現在再次右鍵單擊Developer PowerShell for VS 2019快捷方式和Properties

  • 您將在使用某些命令運行常規 PowerShell 的位置看到:

    C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noe -c "&{Import-Module """C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell bc97b47b}"

在此處輸入圖像描述

現在,如果您打開 PowerShell 並在那里運行腳本:

&{Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"; Enter-VsDevShell bc97b47b}

您將獲得適用於 VS 2019 的 Developer PowerShell,並且 CoreFlags.exe 將起作用:

在此處輸入圖像描述

因此,您需要使用常規 PowerShell 任務(您的選項 2)並在腳本開頭運行上述命令。

注意:您應該准確復制您在Properties中看到的命令,在每台機器上它可能不同。

暫無
暫無

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

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