views:

450

answers:

7

Is there any way to log the number of builds done during a development day in Visual Studio, or anywhere we can hook into something to get at the metadata?

I'm curious how many times on average I build/day * how long it takes per build...

Any thoughts?

UPDATE: sorry for the lack of details...and this exercise is purely academic

With a solution that has 14 different projects (1 is a web site). I am constantly building the entire solution (Ctrl + Shift + B). It would be interesting to find out not only the number of times I build during the day, but how much time is spent waiting for a build to complete...

The optimal solution would be one that doesn't require a change to the solution's projects itself. (pre/post build events) I don't want to have to add/undo changes before/after check-ins.

(The nant/other solution is sounding like the answer, I guess I could map that to a shortcut key and not have to leave VS to do the build)

Any other suggestions?

A: 

It might be overkill, but you can write your own logging utility to log metadata about the build for each project. Keep track of the build count that day through your logging class.

Please see this link about extending MSBuild logging and this link about extending MSBuild with custom tasks.

quinnapi
I've been impressed with what you can do with MSBUild. At one company I worked for, we use MSBuild to to compile a bunch of Flex code when our main project was finished building - that way, we just had to launch one build each day.
Jeff Barger
+7  A: 

One option would be to create a couple of scripts in your favorite scripting language and add them to the pre and post build events of the project settings.

Now every time you run a build the scripts will be run and you can have the scripts track whatever information you require.

But naturally this will only work at a project level and not automatically across all projects.

jussij
You can use the pre-build step to count the number of attempted builds, and the post-build step to count the number of successful builds.
Adam Rosenfield
...and call the same script both pre- and post- to determine how long the build took. ;)
Bob Somers
+1. this was going to be my answer too. Also nice that it can be called separately for each proj in a solution. Can see how many time VisStudio skips building projects that haven't changed.
rally25rs
-1 I don't want to muddy up my build process... I want a solution that is outside the scope of my "project" something that Ideally could be provided by the IDE. (The Macro on a later post is interesting, just can't get it to work...yet)
Jason Jarrett
A: 

If you're building the same project each time, you can easily write a little script to execute in the "Pre-build tasks" section of your Project properties (click the "Build events" button at the bottom of the Compile tab of the properties page).

Mike
A: 

VS only allows you to hook into project level build events so if this isn't enough you can use a build script (MSBuild, NAnt etc) to build the solution which will give you full controll over what happens before and/or after the build.

To be honest though what benifit would you get from these stats on a local machine? We use a build server CCNET http://ccnet.thoughtworks.com/ that tracks build times and Unit test times, and is triggered after a commit to our source control SVN http://www.collab.net/downloads/subversion/ I'd recommend this approach for gathering stats.

Damien McGivern
+2  A: 

Use your macro explorer an edit the EnvironmentEvents Module. You could use a database instead of a file.

Private BuildStopWatch As System.Diagnostics.Stopwatch = New System.Diagnostics.Stopwatch()

Private Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
    BuildStopWatch.Reset()
    BuildStopWatch.Start()
End Sub

Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone
    BuildStopWatch.Stop()
    DTE.ToolWindows.OutputWindow.ActivePane.OutputString("Build succeed in " & BuildStopWatch.Elapsed.TotalSeconds & " seconds.")
    Dim fileName As String = "D:\BuildTimes.txt"
    Try
        Dim streamWriter As StreamWriter
        If File.Exists(fileName) Then
            streamWriter = File.AppendText(fileName)
        Else
            streamWriter = File.CreateText(fileName)
        End If

        streamWriter.WriteLine(DateTime.Now.ToString() & "    " & "Build Time:" & BuildStopWatch.Elapsed.TotalSeconds)
        streamWriter.Close()
        streamWriter.Dispose()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

Is there any tips to get this working? when I place this script in, I don't see anything in the "OutputWindow" and no files is logged...Is there something else I have to do to get this wired up? I think it's what I'm looking for.
Jason Jarrett
Ok, found my "tip" to get it working... I had some other macro in a different location that appeared to cause a conflict and not allow the events to fire. (I commented all extra macros out, not sure which one and why).
Jason Jarrett
A: 

Make sure your EnvironmentsEvents module imports the System.IO namespace to be able to access the StreamWriter and File calls.

A: 

http://www.codeproject.com/KB/macros/Increment_Build_Number.aspx

This worked for me, but be sure to Import the System.IO namespace in your EnvironmentsEvents module as Shawn suggested.