Is there a way to display the build time of an entire solution in Visual Studio?
Asked Answered
M

3

15

I know there is a way to display the build time of each project contained in a solution in visual studio. But what I'm looking for is the total time it took to build an entire solution, from the moment I clicked on build, to the moment it was done.

Is there anyway to do this ? Running Visual Studio 2008.

Morocco answered 21/1, 2010 at 18:30 Comment(0)
A
11

EDIT: Here's a way you can write the build time directly to the build window.

Open the Visual Studio Macro IDE.
Navigate to MyMacros > EnvironmentEvents.
Under MyMacros, add a reference to System.Windows.Forms (for the code below to show a popup window).
Add this code to the EnvironmentEvents module:

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

When you build or rebuild the full solution, at the end, the build/rebuild duration will be printed to the build output window. You can change the conditions in IsBuild to suit your preferences.

Alexio answered 21/1, 2010 at 19:1 Comment(8)
I've added this code to this question as well: https://mcmap.net/q/24974/-awesome-visual-studio-macros-closed I hope others who have similarly useful macros will add them there too. The Visual Studio Macro editor is very powerful, but I haven't run across a good macro repository anywhere.Alexio
EDIT : Weirdly enough, on one of my computers the build ended event is catched... but doesn't pass the IsBuild test, so just returns. I use Visual Assist X on the computer which cannot detect the event, if that makes any difference..Morocco
Open the error list in the Macro IDE (View menu > Error List) and see if any errors are listed. The Macro IDE is kind of weird about errors; quite often it won't give you any sign they exist other than the fact that the macros don't work. Most likely you're missing an Imports statement or something.Alexio
Yeah, so after rechecking I modified my comment... the function is run, but it's just my build isn't recognized in the IsBuild function. There is no error in the error list...Morocco
I output the scope and action : Scope : vsBuildScopeSolution, Action : 0.Morocco
It's wierd how when the build is started, Action is vsBuildActionBuild, but when it ends it becomes 0 ...Morocco
Nothing comes to mind. Obviously, 0 isn't a valid enum value of vsBuildAction; it ranges 1 to 4, and vsBuildScope 1 to 3. Are you using the code exactly as-is, or have you made changes to it?Alexio
I didn't modify the code apart from the debug outputs... I just commented the IsBuild verification for now, I can live with that... Anyhow, thanks for sharing the nice macro!Morocco
Y
3

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

Yaws answered 21/1, 2010 at 18:38 Comment(2)
This outputs the build time of individual projects.Morocco
Some projects are also built in parallel, adding up the times would not work in that case.Aeromancy
K
1

That's an old question but I thought some may still find it useful.

I have written an extension for VS2015 and VS2017. It displays the start and end time for each project, expressed relative to the start of the overall build. Hence the end time of the last project is the total build time for the solution.

I have posted more about the extension here.

Kronick answered 11/1, 2019 at 11:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.