簡體   English   中英

Powershell腳本中的MSBuild - 如何知道構建是否成功?

[英]MSBuild in a Powershell Script - How do I know if the build succeeded?

我正在使用Powershell編寫構建腳本。 這些腳本執行各種操作,例如從SVN獲取最新的源代碼,備份等,並使用MSBuild構建解決方案:

cmd /c C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe "C:\Dev\Path\MyProjct.sln" /p:Configuration=Release 

在這條指令之后,如果編譯成功,我只想執行其余的腳本。 我怎么檢查這個?

該項目是一個Web項目,因此檢查輸出並不容易,但我猜一些變量將包含編譯結果。 此外,因為我用cmd / c調用msbuild,我能夠訪問這些變量嗎?

在調用MSBUILD后$LastExitCode檢查$LastExitCode的值。 如果為0,則MSBUILD成功,否則失敗。

BTW沒有必要使用cmd / c。 只需直接調用MSBUILD.exe即可。 我們一直在PowerShell構建腳本中這樣做。

要檢查成功/失敗,請使用自動變量$?

PS> help about_Automatic_Variables


    $?
       Contains the execution status of the last operation. It contains
    TRUE if the last operation succeeded and FALSE if it failed.

例如:

msbuild
if (! $?) { throw "msbuild failed" }

暫無
暫無

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

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