确定解决方案是否使用 MSBuild 和 PSake 进行编译
我已经整理了一个 PSake (v2.0) 构建脚本,并且该脚本将 $psake.build_success
属性设置为 true
即使对 MSBuild 的调用失败。任何人都可以建议我如何更改脚本,以便在 MSBuild 调用失败时 $psake.build_success
属性正确返回 false
吗?
我的 PSake 构建脚本如下:
properties {
$solutionFile = 'SOLUTION_FILE'
$buildSuccessfulMessage = 'Solution Successfully Built!'
$buildFailureMessage = 'Solution Failed to Build!'
$cleanMessage = 'Executed Clean!'
}
task default -depends BuildSolution
task BuildSolution
{
msbuild $solutionFile /t:Clean,Build
if ($psake.build_success)
{
$buildSuccessfulMessage
}
else
{
$buildFailureMessage
}
}
I have put together a PSake (v2.0) build script, and the script is setting the $psake.build_success
property as true
even thought the call to MSBuild fails. Can anyone advise me on how to alter the script so that the $psake.build_success
property will correctly return false
when the MSBuild call fails?
My PSake build script is as follows:
properties {
$solutionFile = 'SOLUTION_FILE'
$buildSuccessfulMessage = 'Solution Successfully Built!'
$buildFailureMessage = 'Solution Failed to Build!'
$cleanMessage = 'Executed Clean!'
}
task default -depends BuildSolution
task BuildSolution
{
msbuild $solutionFile /t:Clean,Build
if ($psake.build_success)
{
$buildSuccessfulMessage
}
else
{
$buildFailureMessage
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
PowerShell 的本机
$lastExitCode
(即 WIn32 ExitCode)在上下文中有任何用处吗?我猜测内置的命令仅在您调用与 psake 相关的 cmdlet 时才相关。即,将检查替换为
免责声明:只有播客级别的经验与 psake :D
Is PowerShell's native
$lastExitCode
(i.e., WIn32 ExitCode) any use in the context? I'd be guessing that the built in one is only relevant when you're invoking a psake-related cmdlet.i.e., replace the check with
Disclaimer: Only podcast level experience with psake :D
问题似乎是对 MSBuild 操作的调用实际上成功完成,而它启动的构建操作失败。我能够解决此问题的方法是将 MSBuild 调用的输出通过管道传输到文本文件,然后解析文件中的字符串“Build Failed”。如果它包含该字符串,显然构建失败。
我的 PSake 构建脚本如下:
在我的调用脚本中:
The issue seems to be that the call to MSBuild operation actually completes successfully, whilst the build operation it initiates fails. The way I was able to get around this was to pipe the output of the MSBuild call to a text file, and then parse the file for the string "Build Failed". If it contained the string, obviously the build failed.
My PSake build script is as follows:
and in my calling script:
有 psake Exec 命令,您可以用它来包装 msbuild 和一个抛出 powershell 错误。
There is the psake Exec command that you can wrap msbuild with and a powershell error is thrown.
$LastExitCode 或 $_ 都不适合我。然而,这确实是:
PS 如果您在生产中使用它,我建议将 -timeout 处理添加到 Wait-Process
Neither $LastExitCode or $_ worked for me. This did however:
P.S. If you use this in production I recommend adding -timeout handling to Wait-Process