简体   繁体   English

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

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

I am writting a build script with Powershell. 我正在使用Powershell编写构建脚本。 The scripts performs various operations such as getting the latest source code off the SVN, backups, etc., and builds the solution using MSBuild: 这些脚本执行各种操作,例如从SVN获取最新的源代码,备份等,并使用MSBuild构建解决方案:

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

After this instruction, I only want to execute the rest of the script if the compilation succeeded. 在这条指令之后,如果编译成功,我只想执行其余的脚本。 How can I check this? 我怎么检查这个?

The project is a web project, so it's not so easy to check for an output, but I would guess some variables would contain the compilation result. 该项目是一个Web项目,因此检查输出并不容易,但我猜一些变量将包含编译结果。 Also since I call msbuild with cmd /c, am I going to be able to access these variables? 此外,因为我用cmd / c调用msbuild,我能够访问这些变量吗?

Check the value of $LastExitCode right after the call to MSBUILD. 在调用MSBUILD后$LastExitCode检查$LastExitCode的值。 If it is 0, then MSBUILD succeeded, otherwise it failed. 如果为0,则MSBUILD成功,否则失败。

BTW there is no need to use cmd /c. BTW没有必要使用cmd / c。 Just call MSBUILD.exe directly. 只需直接调用MSBUILD.exe即可。 We do that in PowerShell build scripts all the time. 我们一直在PowerShell构建脚本中这样做。

To just check for success/failure, use the automatic variable $? 要检查成功/失败,请使用自动变量$? .

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.

for example: 例如:

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

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

相关问题 MsBuild中的Powershell:检查脚本是否成功? - Powershell in MsBuild: Check if script succeeded? 从后期构建Powershell脚本访问MSBuild - Access MSBuild from Post Build Powershell Script 如何在TFS Build Definition中获取PowerShell脚本任务,以便与x64 MSBuild步骤配合使用? - How to get PowerShell Script Task in TFS Build Definition to play nice with x64 MSBuild step? Powershell Pre-Build脚本从msbuild失败 - Powershell Pre-Build script failing from msbuild 您如何知道 PowerShell 脚本何时完成? - How do you know when PowerShell script finished? 如何在PowerShell中执行MSBuild的GetDirectoryNameOfFileAbove? - How to Do MSBuild's GetDirectoryNameOfFileAbove in PowerShell? 如何在作为VSTS构建/发布的一部分运行的PowerShell脚本中检索变量? - How do I retrieve variables in a PowerShell script running as part of a VSTS build/release? 我如何从TeamCity构建中运行的Powershell脚本收到有意义的错误消息? - How do I have a meaningful error message from powershell script running in TeamCity build? 如何基于脚本参数(即msbuild、gradle)在powershell中实现任务 - How to implement tasks in powershell based on a script parameter (i.e. msbuild, gradle) 我怎样才能更好地完成这个 powershell 脚本? - How I can do this powershell script better?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM