【问题标题】:Is there a way to display the build time of an entire solution in Visual Studio?有没有办法在 Visual Studio 中显示整个解决方案的构建时间?
【发布时间】:2011-01-07 21:11:04
【问题描述】:

我知道有a way to display the build time of each project contained in a solution in visual studio。但我正在寻找的是构建整个解决方案所花费的总时间,从我点击构建的那一刻到完成的那一刻。

有没有办法做到这一点?运行 Visual Studio 2008。

【问题讨论】:

    标签: visual-studio visual-studio-2008 build-time


    【解决方案1】:

    Tools->Options->Projects and Solutions->VC++ Project Settings->Build Timing

    【讨论】:

    • 这会输出各个项目的构建时间。
    • 有些项目也是并行构建的,这种情况下时间累加是行不通的。
    【解决方案2】:

    编辑:这是一种将构建时间直接写入构建窗口的方法。

    打开 Visual Studio 宏 IDE。
    导航到 MyMacros > EnvironmentEvents。
    在 MyMacros 下,添加对 System.Windows.Forms 的引用(以便下面的代码显示弹出窗口)。
    将此代码添加到 EnvironmentEvents 模块:

    Dim buildStart As Date
    
    Private Function IsBuild(ByVal scope As EnvDTE.vsBuildScope, ByVal action As EnvDTE.vsBuildAction) As Boolean
        Return scope = vsBuildScope.vsBuildScopeSolution AndAlso (action = vsBuildAction.vsBuildActionBuild OrElse action = vsBuildAction.vsBuildActionRebuildAll)
    End Function
    
    Private Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
        If (IsBuild(Scope, Action)) Then
            buildStart = Date.Now
        End If
    End Sub
    
    Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone
        If (IsBuild(Scope, Action)) Then
            Dim buildTime = Date.Now - buildStart
            WriteToBuildWindow(String.Format("Build time: {0}", buildTime.ToString))
        End If
    End Sub
    
    Private Sub WriteToBuildWindow(ByVal message As String)
        Dim win As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
        Dim ow As OutputWindow = CType(win.Object, OutputWindow)
        For Each owPane As OutputWindowPane In ow.OutputWindowPanes
            If (owPane.Name.Equals("Build")) Then
                owPane.OutputString(message)
                Exit For
            End If
        Next
    End Sub
    

    当您构建或重建完整的解决方案时,最后,构建/重建持续时间将打印到构建输出窗口。您可以根据自己的喜好更改 IsBuild 中的条件。

    【讨论】:

    • 我也将此代码添加到此问题中:stackoverflow.com/questions/523220/awesome-visual-studio-macros 我希望其他有类似有用宏的人也将它们添加到那里。 Visual Studio 宏编辑器非常强大,但我没有在任何地方运行过好的宏存储库。
    • 编辑:奇怪的是,在我的一台计算机上,构建结束事件被捕获......但没有通过 IsBuild 测试,所以只是返回。我在无法检测到事件的计算机上使用 Visual Assist X,如果这有什么不同的话..
    • 在宏 IDE 中打开错误列表(查看菜单 > 错误列表),查看是否列出了任何错误。宏 IDE 对错误有点奇怪。除了宏不起作用的事实之外,它通常不会给您任何它们存在的迹象。您很可能缺少 Imports 声明或其他内容。
    • 是的,所以在重新检查后我修改了我的评论......该函数已运行,但只是我的构建在 IsBuild 函数中无法识别。错误列表中没有错误...
    • 我输出范围和动作:范围:vsBuildScopeSolution,动作:0。
    【解决方案3】:

    这是一个老问题,但我认为有些人可能仍然觉得它有用。

    我已经为 VS2015 和 VS2017 编写了一个扩展。它显示每个项目的开始和结束时间,相对于整个构建的开始表示。因此,最后一个项目的结束时间就是解决方案的总构建时间。

    我已经发布了更多关于扩展 here 的信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      • 1970-01-01
      相关资源
      最近更新 更多