[英]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.