簡體   English   中英

在從構建事件調用的 powershell 腳本中使用 Visual Studio 宏

[英]Use Visual Studio macros in powershell scripts called from build event

我想在 Visual Studio 的構建事件中使用 powershell 腳本,並且我需要使用一些在 Visual Studio 本身中定義的宏。

這是我的 powershell 腳本示例:

"Updating version for Project:"
"$ProjectDir"

然后在項目的預構建事件中,我以這種方式調用它:

powershell.exe -file "$(SolutionDir)Resources\UpdateVersion.ps1" -path $(SolutionDir)

構建項目時,我正確調用了腳本,但包含項目路徑的字符串為空。

有沒有辦法將所有 Visual Studio 宏傳遞給 powershell 腳本,而不將它們顯式地作為腳本參數傳遞(我必須使用很多宏,這會很乏味)?

一個遲到的答案,但我希望它可以幫助某人。

在您的 Pre-Build 事件中,您使用“-path”參數傳遞 $(SolutionDir),但在 PowerShell 腳本中,您從不使用“-path”參數。 看起來您試圖將其引用為“$ProjectDir”。

解釋如何在 PowerShell 中使用命名參數超出了這個問題的范圍,所以我將切換到使用位置參數。

將您的 PowerShell 腳本更改為:

param($solution, $project)
Write-Host $solution
Write-Host $project

然后,將您的構建事件更改為:

powershell.exe -file "$(SolutionDir)Resources\UpdateVersion.ps1" $(SolutionDir) $(ProjectDir)

暫無
暫無

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

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