Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Solution Build Timer for VS2005

, 21 Aug 2008
Add-in for VS2005 that provides the time taken to build a complete solution.
SolutionBuildTimer.zip
SolutionBuildTimer
bin
Setup
SolutionBuildTimer.iss
SolutionBuildTimerSetup.exe
SolutionBuildTimer.AddIn
��using System;

using Extensibility;

using EnvDTE;

using EnvDTE80;

namespace SolutionBuildTimer

{

	/// <summary>The object for implementing an Add-in.</summary>

	/// <seealso class='IDTExtensibility2' />

	public class Connect : IDTExtensibility2

	{

		/// <summary>Implements the constructor for the Add-in object. Place your initialization code within this method.</summary>

		public Connect()

		{

		}



		/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>

		/// <param term='application'>Root object of the host application.</param>

		/// <param term='connectMode'>Describes how the Add-in is being loaded.</param>

		/// <param term='addInInst'>Object representing this Add-in.</param>

		/// <seealso class='IDTExtensibility2' />

		public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)

		{

			_applicationObject = (DTE2)application;

			_addInInstance = (AddIn)addInInst;



			// We want our output in the Build window

			OutputWindow outputWindow = (OutputWindow)_applicationObject.Windows.Item(Constants.vsWindowKindOutput).Object;

			outputWindowPane = outputWindow.OutputWindowPanes.Item("Build");

			// Add ourselves as a OnBuildBegin/OnBuildDone handler

			EnvDTE.Events events = _applicationObject.Events;

			buildEvents = (EnvDTE.BuildEvents)events.BuildEvents;

			buildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(this.OnBuildBegin);

			buildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(this.OnBuildDone);

		}



		/// <summary>Implements the OnDisconnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being unloaded.</summary>

		/// <param term='disconnectMode'>Describes how the Add-in is being unloaded.</param>

		/// <param term='custom'>Array of parameters that are host application specific.</param>

		/// <seealso class='IDTExtensibility2' />

		public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)

		{

			// Remove ourselves as a OnBuildBegin/OnBuildEnd handler

			if (buildEvents != null)

			{

				buildEvents.OnBuildBegin -= new _dispBuildEvents_OnBuildBeginEventHandler(this.OnBuildBegin);

				buildEvents.OnBuildDone -= new _dispBuildEvents_OnBuildDoneEventHandler(this.OnBuildDone);

			}

		}



		/// <summary>Implements the OnAddInsUpdate method of the IDTExtensibility2 interface. Receives notification when the collection of Add-ins has changed.</summary>

		/// <param term='custom'>Array of parameters that are host application specific.</param>

		/// <seealso class='IDTExtensibility2' />		

		public void OnAddInsUpdate(ref Array custom)

		{

		}



		/// <summary>Implements the OnStartupComplete method of the IDTExtensibility2 interface. Receives notification that the host application has completed loading.</summary>

		/// <param term='custom'>Array of parameters that are host application specific.</param>

		/// <seealso class='IDTExtensibility2' />

		public void OnStartupComplete(ref Array custom)

		{

		}



		/// <summary>Implements the OnBeginShutdown method of the IDTExtensibility2 interface. Receives notification that the host application is being unloaded.</summary>

		/// <param term='custom'>Array of parameters that are host application specific.</param>

		/// <seealso class='IDTExtensibility2' />

		public void OnBeginShutdown(ref Array custom)

		{

    }

		

		private DTE2 _applicationObject;

		private AddIn _addInInstance;

		private OutputWindowPane outputWindowPane;

		private EnvDTE.BuildEvents buildEvents;

		private bool amTiming = false;

		private DateTime dtStart, dtEnd;



		// BuildEvents

		public void OnBuildBegin(EnvDTE.vsBuildScope Scope, EnvDTE.vsBuildAction Action)

		{

			// Check for a solution build for Build or RebuildAll

			if (EnvDTE.vsBuildScope.vsBuildScopeSolution == Scope &&

				(EnvDTE.vsBuildAction.vsBuildActionBuild == Action || EnvDTE.vsBuildAction.vsBuildActionRebuildAll == Action))

			{

				// Flag our build timer

				amTiming = true;

				dtStart = DateTime.Now;

				outputWindowPane.OutputString(String.Format("Starting timed solution build on {0}\n", dtStart));

			}

		}



		public void OnBuildDone(EnvDTE.vsBuildScope Scope, EnvDTE.vsBuildAction Action)

		{

			// Check if we are actually timing this build

			if (amTiming)

			{

				amTiming = false;

				dtEnd = DateTime.Now;

				outputWindowPane.OutputString(String.Format("Ended timed solution build on {0}\n", dtEnd));

				TimeSpan tsElapsed = dtEnd - dtStart;

				outputWindowPane.OutputString(String.Format("Total build time: {0}\n", tsElapsed));

			}

		}

	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Brett Rowbotham
Architect Knowledge Base Software
South Africa South Africa
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 22 Aug 2008
Article Copyright 2008 by Brett Rowbotham
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid