如何显示 Visual Studio 在线构建任务 Write-Verbose 语句?

How to show Visual Studio Online build task Write-Verbose statements?

许多 Visual Studio 在线 (VSO) build tasks use Write-Verbose for debugging purposes as seen in this example,但是如何打开 Write-Verbose 以便调试语句出现在输出日志中?

(只是将评论移至答案)

由于脚本有参数,但没有 CmdletBinding,也没有 [Parameter(...)],因此 -Verbose 不被接受。

解决方法:在params前添加[CmdletBinding()]或添加一个[Parameter(Mandatory=$true)]或类似于一个或多个单独参数变量的内容。

来自about_parameters

All attributes are optional. However, if you omit the CmdletBinding attribute, then to be recognized as an advanced function, the function must include the Parameter attribute.

about_Functions_CmdletBindingAttribute 有更多关于赋予 cmdlet 的能力的信息。

要在日志中显示详细和调试语句,您只需将 System.Debug 变量添加到您定义的变量中。

以下是对我有用的方法:

  1. 在脚本中使用 Write-Verbose "Text" -Verbose
  2. 将构建变量 system.debug 分配给 true