Written by: 18 January 2012 14:20
In Visual Studio we can create macros that plug in to the Evironment Events. The Macro in this blog post will output to the Build window the date and time the Process was completed. Whilst the macro is simple it is a great starting point for Building more macros that utilise the Visual Studio IDE.
Option
Strict Off
Explicit Off
Imports
System
EnvDTE
EnvDTE80
EnvDTE90
EnvDTE90a
EnvDTE100
System.Diagnostics
System.IO
Public
Module
EnvironmentEvents
#Region "Automatically generated code, do not modify"
'Automatically generated code, do not modify
'Event Sources Begin
WithEvents
DTEEvents
As
EnvDTE.DTEEvents
DocumentEvents
EnvDTE.DocumentEvents
WindowEvents
EnvDTE.WindowEvents
TaskListEvents
EnvDTE.TaskListEvents
FindEvents
EnvDTE.FindEvents
OutputWindowEvents
EnvDTE.OutputWindowEvents
SelectionEvents
EnvDTE.SelectionEvents
BuildEvents
EnvDTE.BuildEvents
SolutionEvents
EnvDTE.SolutionEvents
SolutionItemsEvents
EnvDTE.ProjectItemsEvents
MiscFilesEvents
DebuggerEvents
EnvDTE.DebuggerEvents
ProjectsEvents
EnvDTE.ProjectsEvents
TextDocumentKeyPressEvents
EnvDTE80.TextDocumentKeyPressEvents
CodeModelEvents
EnvDTE80.CodeModelEvents
DebuggerProcessEvents
EnvDTE80.DebuggerProcessEvents
DebuggerExpressionEvaluationEvents
EnvDTE80.DebuggerExpressionEvaluationEvents
'Event Sources End
'End of automatically generated code
#End Region
Dim
_startTime
DateTime
Private
Sub
BuildEvents_OnBuildBegin(
ByVal
Scope
EnvDTE.vsBuildScope,
Action
EnvDTE.vsBuildAction)
Handles
BuildEvents.OnBuildBegin
_startTime = DateTime.Now
WriteState(
String
.Format(
"Start Build : {0}"
, _startTime.ToString(
"dd MMM yyyy HH:mm:ss"
)))
End
BuildEvents_OnBuildDone(
BuildEvents.OnBuildDone
endTime
DateTime = DateTime.Now
timeSpent
TimeSpan =
CType
((endTime - _startTime), TimeSpan)
total
Decimal
= GetPreviousTime() + Convert.ToDecimal(timeSpent.TotalSeconds)
"End Build : {0}"
, endTime.ToString(
"Total BuildTime : {0}"
, timeSpent.TotalSeconds))
WriteToLogFile(
"{0}, {1}, {2}"
), timeSpent.TotalSeconds.ToString(), total))
BuildEvents_OnBuildProjConfigDone(
Project
,
ProjectConfig
Platform
SolutionConfig
Success
Boolean
)
BuildEvents.OnBuildProjConfigDone
If
Success =
False
Then
'The build failed...cancel any further builds.
DTE.ExecuteCommand(
"Build.Cancel"
"Build failed - Build process halted for project {0}"
, Project))
Function
GetOutputWindow()
OutputWindow
Return
DTE.Windows.Item(Constants.vsWindowKindOutput).
Object
()
GetActivePane()
OutputWindowPane
GetOutputWindow.ActivePane
message
GetActivePane.OutputString(
.Format(message) & vbCrLf)
GetPreviousTime()
fi
New
FileInfo(DTE.Solution.FullName)
fileName
=
"c:\\{0}.build.log"
, fi.Name)
(File.Exists(fileName) =
0
Using sr =
StreamReader(fileName,
True
lastString
While
(
Not
sr.EndOfStream)
lastString = sr.ReadLine()
sr.Close()
(lastString =
.Empty)
characters()
Char
= {
","
c}
strings()
= lastString.Split(characters)
totalString
= strings(strings.Length - 1)
= Convert.ToDecimal(totalString)
Using
Using sw =
StreamWriter(
"c:\\" & fi.Name & "
.build.log",
sw.WriteLine(message)
sw.Flush()
sw.Close()
0 comment(s) so far...