views:

176

answers:

2

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.

A: 

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

Goz
This outputs the build time of individual projects.
JC
Bugger ... Well, you could add them all up by hand ... not THAT hard to do ...
Goz
Yeah, but I'm lazy... there's about 30 projects in my solution...
JC
+2  A: 

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.

Kyralessa
I've added this code to this question as well: http://stackoverflow.com/questions/523220/awesome-visual-studio-macros 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.
Kyralessa
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..
JC
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.
Kyralessa
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...
JC
I output the scope and action : Scope : vsBuildScopeSolution, Action : 0.
JC
It's wierd how when the build is started, Action is vsBuildActionBuild, but when it ends it becomes 0 ...
JC
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?
Kyralessa
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!
JC