Wednesday, August 4, 2010

Adding DLL reference automatically

It's quite sad when you are trying to add new reference by using the Add Reference provided in the Visual Studio because it is very slow. To speed up the process, you may have to add the following Macro and run it manually. It will add all your Dll references in one click:

    '4-8-10,lhw
'-add the commonly used dll to the selected project.
' No need to go through the Add Reference screen in VS.
Sub AddGeneralReferences()
Dim proj As EnvDTE.Project
Dim arr As Array = DTE.ActiveSolutionProjects

If Not arr Is Nothing Then
If arr.Length > 0 Then
proj = arr(0)

If Not proj Is Nothing Then
Dim v As VSLangProj.VSProject = proj.Object
Dim r As VSLangProj.References = v.References

If Not r Is Nothing Then
r.Add("System.configuration")
r.Add("System.Drawing")

'not sure why must include the
'full reference to system.web dll.
'Otherwise, COM error will occur.
r.Add("C:\WINDOWS\Microsoft.NET" & _
"\Framework\v2.0.50727\System.Web.dll")

r.Add("System.Web.Services")
End If
End If
End If
End If
End Sub

No comments:

Post a Comment