Option Strict Off Option Explicit On Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports System.Diagnostics Imports System.IO Public Module EnvironmentEvents #Region "Automatically generated code, do not modify" 'Automatically generated code, do not modify 'Event Sources Begin Public WithEvents DTEEvents As EnvDTE.DTEEvents Public WithEvents DocumentEvents As EnvDTE.DocumentEvents Public WithEvents WindowEvents As EnvDTE.WindowEvents Public WithEvents TaskListEvents As EnvDTE.TaskListEvents Public WithEvents FindEvents As EnvDTE.FindEvents Public WithEvents OutputWindowEvents As EnvDTE.OutputWindowEvents Public WithEvents SelectionEvents As EnvDTE.SelectionEvents Public WithEvents BuildEvents As EnvDTE.BuildEvents Public WithEvents SolutionEvents As EnvDTE.SolutionEvents Public WithEvents SolutionItemsEvents As EnvDTE.ProjectItemsEvents Public WithEvents MiscFilesEvents As EnvDTE.ProjectItemsEvents Public WithEvents DebuggerEvents As EnvDTE.DebuggerEvents Public WithEvents ProjectsEvents As EnvDTE.ProjectsEvents Public WithEvents TextDocumentKeyPressEvents As EnvDTE80.TextDocumentKeyPressEvents Public WithEvents CodeModelEvents As EnvDTE80.CodeModelEvents Public WithEvents DebuggerProcessEvents As EnvDTE80.DebuggerProcessEvents Public WithEvents DebuggerExpressionEvaluationEvents As EnvDTE80.DebuggerExpressionEvaluationEvents 'Event Sources End 'End of automatically generated code #End Region Dim _startTime As DateTime Private Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin _startTime = DateTime.Now WriteState(String.Format("Start Build : {0}", _startTime.ToString("dd MMM yyyy HH:mm:ss"))) End Sub Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone Dim endTime As DateTime = DateTime.Now Dim timeSpent As TimeSpan = CType((endTime - _startTime), TimeSpan) Dim total As Decimal = GetPreviousTime() + Convert.ToDecimal(timeSpent.TotalSeconds) WriteState(String.Format("End Build : {0}", endTime.ToString("dd MMM yyyy HH:mm:ss"))) WriteState(String.Format("Total BuildTime : {0}", timeSpent.TotalSeconds)) WriteToLogFile(String.Format("{0}, {1}, {2}", _startTime.ToString("dd MMM yyyy HH:mm:ss"), timeSpent.TotalSeconds.ToString(), total)) End Sub Private Sub BuildEvents_OnBuildProjConfigDone(ByVal Project As String, ByVal ProjectConfig As String, ByVal Platform As String, ByVal SolutionConfig As String, ByVal Success As Boolean) Handles BuildEvents.OnBuildProjConfigDone If Success = False Then 'The build failed...cancel any further builds. DTE.ExecuteCommand("Build.Cancel") WriteState(String.Format("Build failed - Build process halted for project {0}", Project)) End If End Sub Function GetOutputWindow() As OutputWindow Return DTE.Windows.Item(Constants.vsWindowKindOutput).Object() End Function Function GetActivePane() As OutputWindowPane Return GetOutputWindow.ActivePane End Function Private Sub WriteState(ByVal message As String) GetActivePane.OutputString(String.Format(message) & vbCrLf) End Sub Private Function GetPreviousTime() As Decimal Dim fi As New FileInfo(DTE.Solution.FullName) Dim fileName As String = String.Format("c:\\{0}.build.log", fi.Name) If (File.Exists(fileName) = False) Then Return 0 End If Using sr = New StreamReader(fileName, True) Dim lastString As String While (Not sr.EndOfStream) lastString = sr.ReadLine() End While sr.Close() If (lastString = String.Empty) Then Return 0 End If Dim characters() As Char = {","c} Dim strings() As String = lastString.Split(characters) Dim totalString As String = strings(strings.Length - 1) Dim total As Decimal = Convert.ToDecimal(totalString) Return total End Using End Function Private Sub WriteToLogFile(ByVal message As String) Dim fi As New FileInfo(DTE.Solution.FullName) Using sw = New StreamWriter("c:\\" & fi.Name & ".build.log", True) sw.WriteLine(message) sw.Flush() sw.Close() End Using End Sub End Module