gpt4 book ai didi

powershell - psake报错

转载 作者:行者123 更新时间:2023-12-03 13:42:09 26 4
gpt4 key购买 nike

如何在 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
}
}

最佳答案

这就是我处理这个问题的方式。首先,在这个异常吞噬代码之前的某个地方,创建一个名为 $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

}

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

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

关于powershell - psake报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29926946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com