Click here to Skip to main content
12,299,397 members (54,414 online)
Click here to Skip to main content

Stats

37.4K views
594 downloads
22 bookmarked
Posted

Solution Build Timer for VS2005/2013/2015

, 25 Feb 2016 CPOL
Add-in for VS2005 or VS2013/2015 that provides the time taken to build a complete solution
SolutionBuildTimer
bin
Setup
SolutionBuildTimer.iss
SolutionBuildTimerSetup.exe
SolutionBuildTimer.AddIn
Key.snk
Properties
Resources
Package.ico
SolutionBuildTimer.csproj.user
source.extension.vsixmanifest
SolutionBuildTimer.vsix
��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

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 26 Feb 2016
Article Copyright 2008 by Brett Rowbotham
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid