Avoid the slow Add Reference dialog box in Visual Studio 2008
28 Nov 2009
When you are in the zone, and want to add a reference to Rhino, NUnit or any other common reference, adding it via the Add Reference dialog can be painfully slow. Fortunately VS has a good automation interface, which lets you to write macros.
I wrote a simple macro to add a NUnit reference to the current project. Add this to your Macros project in Visual Studio, map a button or a shortcut key to it. This way you can add those common references pretty quick.
This is a cleaned up version of the sample here http://msdn.microsoft.com/en-us/library/vslangproj80.reference3%28VS.80%29.aspx
1: Sub AddNUnitReference()
2: AddNewReference(DTE, "C:\Tools\NUnit\nunit.framework.dll")
3: End Sub
4:
5: Sub AddNewReference(ByVal dte As DTE2, ByVal referencePath As String)
6: Dim aProject As Project
7: Dim aVSProject As VSProject
8:
9: aProject = dte.ActiveDocument.ProjectItem.ContainingProject
10:
11: aVSProject = CType(dte.ActiveDocument.ProjectItem.ContainingProject.Object, VSProject)
12: ' Add an Assembly reference and display its type and additional
13: ' information.
14: Dim newRef As Reference
15: newRef = aVSProject.References.Add(referencePath)
16:
17: End Sub