如果要调用可以跟踪总构建时间的外部程序,则可以对VS 2010使用以下解决方案(可能更旧)。下面的代码使用Casey Muratori的CTime。当然,您也可以使用它来简单地打印构建时间。
打开宏资源管理器,然后粘贴以下内容End Module
:
Dim buildStart As Date
Private Sub RunCtime(ByVal StartRatherThanEnd As Boolean)
Dim Arg As String
Dim psi As New System.Diagnostics.ProcessStartInfo("ctime.exe")
If StartRatherThanEnd Then
psi.Arguments = "-begin"
Else
psi.Arguments = "-end"
End If
psi.Arguments += " c:\my\path\build.ctm"
psi.RedirectStandardOutput = False
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.UseShellExecute = False
psi.CreateNoWindow = True
Dim process As System.Diagnostics.Process
process = System.Diagnostics.Process.Start(psi)
Dim myOutput As System.IO.StreamReader = process.StandardOutput
process.WaitForExit(2000)
If process.HasExited Then
Dim output As String = myOutput.ReadToEnd
WriteToBuildWindow("CTime output: " + output)
End If
End Sub
Private Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
WriteToBuildWindow("Build started!")
buildStart = Date.Now
RunCtime(True)
End Sub
Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone
Dim buildTime = Date.Now - buildStart
WriteToBuildWindow(String.Format("Total build time: {0} seconds", buildTime.ToString))
RunCtime(False)
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)
If (Not message.EndsWith(vbCrLf)) Then
message = message + vbCrLf
End If
ow.OutputWindowPanes.Item("Build").OutputString(message)
End Sub
从这里到这里的答案。