3

如何在psake任务列表中的任何任务中收到任何错误通知。?

在通知处理程序中,我想显示任务失败的窗口通知。但是 psake 吞下了异常并将其写入控制台。

更新: 这是吞下错误的 Psake 构建脚本中的代码

 # if we are running in a nested scope (i.e. running a psake script from a psake script) then we need to re-throw the exception
        # so that the parent script will fail otherwise the parent script will report a successful build 
        $inNestedScope = ($psake.context.count -gt 1)
        if ( $inNestedScope ) {
            throw $_
        } else {
            if (!$psake.run_by_psake_build_tester) {
                WriteColoredOutput $error_message -foregroundcolor Red
            }
        }
4

1 回答 1

1

这就是我处理这个问题的方式。首先,在这个异常吞咽代码之前的某个地方,创建一个名为 $errors 的新对象,它是一个 ArrayList 类型(对于构建消息集合非常有用且快速)。

$errors = New-Object System.Collections.ArrayList
# if we are running in a nested scope (i.e. running a psake script from a psake script) then we need to re-throw the exception
        # so that the parent script will fail otherwise the parent script will report a successful build 
        $inNestedScope = ($psake.context.count -gt 1)
        if ( $inNestedScope ) {
            throw $_
        } else {
            if (!$psake.run_by_psake_build_tester) {
                WriteColoredOutput $error_message -foregroundcolor Red
                $errors.Add($error[0])
            }
        }

        <#.the rest of your code...#>

       if ($errors.Count -ne 0){
        Write-Warning 'A number of errors were encountered during the processing of this task, please review them, below'
        $errors

       }

这是一种非常简单的方法,可能会完成工作。我们仍然允许将错误写到屏幕上,但也将它们全部收集起来以显示在脚本的其他地方。

如果这种方法不是您想要的,请告诉我?

于 2015-04-29T12:13:09.493 回答