【问题标题】:Can Visual Studio put timestamps in the build log?Visual Studio 可以在构建日志中添加时间戳吗?
【发布时间】:2010-09-07 23:20:19
【问题描述】:

在构建日志中,我想记录每个项目编译的开始和结束时间。有没有办法让 VS 做到这一点?

【问题讨论】:

    标签: visual-studio build


    【解决方案1】:

    其他选项是提高 MSBuild 详细程度。

    Tools -> Options -> Projects and Solutions -> Build and Run -> 
    

    MSBuild project build output verbosity 设置为Normal。这会给你这样的输出:

    ------ Build started: MyProject, Configuration: Debug x86 ------
    Build started 24/03/2014 08:46:18.
    ...
    Build succeeded.
    
    Time Elapsed 00:00:05.18
    

    【讨论】:

    • 谢谢,这实际上符合 OP 的要求。
    • 这应该是默认的。我经常发现查看解决方案/项目的最后构建时间很重要,以确保我正在运行当前版本。可以检查我认为的构建工件:D
    【解决方案2】:

    对于 VC++ 构建,您可以启用构建时序。转到工具->选项->项目和解决方案->VC++项目设置并选择“构建时序”选项

    【讨论】:

    • 请注意,这实际上并没有将 timestamps 放入构建日志中。但是它会报告每个步骤中使用的毫秒数。
    【解决方案3】:

    我发现的一种新方法是在 post event PrePost-build event 命令行中调用Time 命令:

    TIME /T
    

    【讨论】:

    • 如果您还想显示日期,可以使用“DATE /T”来完成。
    • 由于没有发出构建结束日期/时间戳,构建后建议有所帮助,为什么开始进行不必要的心理体操,即在构建中添加经过的时间?
    【解决方案4】:

    必须修改实际项目文件(使用文本编辑器)以将调用添加到 MSBuild 脚本目标。

    【讨论】:

      【解决方案5】:

      脚本文件的替代解决方案... 还包括项目构建的经过时间。

      在项目共享空间“GetTime.vbs”的某处创建 VBS 文件 VBS 代码 ...

      dim out : Set out = WScript.StdOut
      Set objShell = WScript.CreateObject("WScript.Shell")
      dim regDir: regDir="HKEY_CURRENT_USER\Software\VB and VBA Program Settings\GetTime.vbs\"
      dim msg: msg=""
      dim s: s=""
      dim e: e=""
      dim st:st=""
      ' param s is start flag keyed to the application being built.
      if wscript.arguments.named.exists("s") then
          s = wscript.arguments.named("s")
          objShell.RegWrite regdir & s,now
      end if
      if wscript.arguments.named.exists("e") then
          e = wscript.arguments.named("e")
          st = cdate(objShell.RegRead(regDir & e))
      end if 
      
      if e<>"" and isdate(st) then
          out.writeline e & " ENDED " & now & " ELAPSED " & datediff("s",cdate(st),now) & " seconds"
      elseif e<>"" then
          out.writeline e & " ENDED " & now
      elseif s<>"" then
          out.writeline s & " STARTED " & now
      else
          out.writeline now
      end if 
      

      更改您的构建事件以包含此脚本和一些参数,例如... (您将需要更改相对于输出目录的目录路径以从多个项目中查找文件)

      预构建事件命令行 ...

      cscript "../../../../Scorecards/gettime.vbs" //B /s:"$(ProjectName)"
      

      构建后事件命令行

      cscript "../../../../Scorecards/gettime.vbs" //B /e:"$(ProjectName)"
      

      来自多个项目的示例输出 ...

      2>  OPResources STARTED 7/9/2020 12:59:04 PM
      2>  ...
      2>  OPResources ENDED 7/9/2020 12:59:05 PM ELAPSED 1 seconds
      1>  OPLib_WF STARTED 7/9/2020 12:59:04 PM
      1>  ...
      1>  OPLib_WF ENDED 7/9/2020 12:59:05 PM ELAPSED 1 seconds
      4>------ Rebuild All started: Project: OPLib, Configuration: Debug Any CPU ------
      4>  OPLib STARTED 7/9/2020 12:59:06 PM
      4> ...
      4>  OPLib ENDED 7/9/2020 12:59:10 PM ELAPSED 4 seconds
      5>------ Rebuild All started: Project: PerfUpdater, Configuration: Debug Any CPU ------
      6>------ Rebuild All started: Project: Scorecards2, Configuration: Debug Any CPU ------
      7>------ Rebuild All started: Project: SingleSignOn, Configuration: Debug Any CPU ------
      7>  SingleSignOn STARTED 7/9/2020 12:59:10 PM
      7>  ...
      7>  SingleSignOn ENDED 7/9/2020 12:59:12 PM ELAPSED 2 seconds
      

      【讨论】:

        猜你喜欢
        • 2015-08-30
        • 2021-07-10
        • 1970-01-01
        • 2020-08-18
        • 2012-12-24
        • 2016-02-26
        • 2016-11-10
        • 1970-01-01
        • 2016-08-04
        相关资源
        最近更新 更多