4

我在 msbuild 中有构建脚本,它将由 powershell 调用。

构建日志文件看起来像这样。

构建于 2011 年 12 月 19 日下午 2:01:54 开始。

构建成功。0 警告 0 错误

经过时间 00:00:00.28

在起点,它将指定构建执行的启动时间,结束时它会说 Time elapsed。

我想使用 powershell 或 msbuild 查找执行时间。如何添加所有经过的时间值或找到上次构建开始发生与首次构建发生之间的差异?

因为它在日志文件中,我不知道如何检索和测量。

4

2 回答 2

6

请注意,如果您使用 Measure-Command { },它将使用您构建的控制台输出。所以任何输出都会消失。

一种不那么侵入性的方法是简单地减去 Get-Date 值。例如,这将是您的 build.ps1 脚本:

$before = Get-Date
<your build command line>
$after = Get-Date

$time = $after - $before
$buildTime = "`nBuild finished in ";
if ($time.Minutes -gt 0)
{
    $buildTime += "{0} minute(s) " -f $time.Minutes;
}

$buildTime += "{0} second(s)" -f $time.Seconds;
于 2011-12-19T22:25:50.647 回答
5

用于Measure-Commmand查看您的构建过程需要多长时间。这是一个例子:

Measure-Command { ./build.ps1 }

我机器上的输出是:

PS D:\> Measure-Command { ./build.ps1 }


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 6
Milliseconds      : 443
Ticks             : 64439301
TotalDays         : 7.45825243055556E-05
TotalHours        : 0.00178998058333333
TotalMinutes      : 0.107398835
TotalSeconds      : 6.4439301
TotalMilliseconds : 6443.9301
于 2011-12-19T09:06:20.827 回答