Powershell psake中的错误报告

Powershell psake中的错误报告,powershell,psake,Powershell,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 par

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

在通知处理程序中,我想显示任务失败的窗口通知。但是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
            }
        }

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

$errors=新对象System.Collections.ArrayList
#如果我们在嵌套的范围内运行(即从psake脚本运行psake脚本),那么我们需要重新抛出异常
#因此父脚本将失败,否则父脚本将报告成功的生成
$inNestedScope=($psake.context.count-gt 1)
如果($inNestedScope){
扔$_
}否则{
if(!$psake.run_psake_build_tester){
WriteColoredOutput$error_消息-foregroundcolor红色
$errors.Add($error[0])
}
}
如果($errors.Count-ne 0){
写入警告“处理此任务时遇到许多错误,请在下面查看”
$errors
}
这是一个非常简单的方法,可能会完成工作。我们仍然允许将错误写到屏幕上,但也会收集所有错误以显示在脚本的其他地方


如果这种方法不是你想要的,请让我知道?

你能告诉我诗篇中哪一行是错误的吗?如果是这样的话,我可以帮助您对代码进行一个小的更改,以便将错误传递到其他地方以供使用。@FoxDeploy。用psake中的代码更新了问题
$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

       }