brady gaster

yadnb

Programmatically Adding References (Macro-related)

If the name of the post doesn't sum it all the way up, here's the question. Does anyone know of a way, in macro code, to programmatically add a reference to a project? That'd be swell, eh? Takers?

Comments

Matt Berther said:

Isnt the project file just xml?

Just add <Reference Name="" AssemblyName="" HintPath=""/> elements to the References node.
# December 31, 2003 2:25 PM

adam said:

It's hidden in the VSLangProj.VSProject class.

Public Module Module1
Public Function AddProjectReference()
Dim selItems As EnvDTE.SelectedItems
selItems = DTE.SelectedItems

If selItems.Count = 1 Then
Dim project As Project
project = selItems.Item(0).Project

Dim vsProj As VSLangProj.VSProject
vsProj = DirectCast(project.Object, VSLangProj.VSProject)

vsProj.References.Add("path to reference")
End If
End Function
End Module
# December 31, 2003 10:10 PM

brady gaster said:

VERY nice indeed! Danke!
# January 1, 2004 12:20 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)