References::AddProject Method (Project^)

 

Adds a new project reference to the project and returns the newly created Reference object.

Namespace:   VSLangProj
Assembly:  VSLangProj (in VSLangProj.dll)

Reference^ AddProject(
	Project^ pProject
)

Parameters

pProject
Type: EnvDTE::Project^

Required. The Project object to be added.

Return Value

Type: VSLangProj::Reference^

This method does not generate an error if a reference exists in the project with the same Identity, Culture, MajorVersion, MinorVersion, BuildNumber, and RevisionNumber as the new reference. That condition would indicate that the reference indicated by the bstrPath parameter has already been added to the project. Instead, the ProjectItem for the matching reference already in the project is returned.

If a reference with the same Identity but differing MajorVersion, MinorVersion, BuildNumber, RevisionNumber or Culture is found in the project, the method generates an error.

' Macro Editor    
Imports VSLangProj
' Add the second project as a reference to the first project.
Sub AddProjectExample()
   ' First project is a Visual Basic or C# project.
   Dim theVSProject As VSProject = _
      CType(DTE.Solution.Projects.Item(1).Object, VSProject)

   ' Second project is any type of project.
   Dim secondProject As Project = DTE.Solution.Projects.Item(2)

   ' AddProject returns the newly created Reference object.
   Dim newReference As Reference
   newReference = theVSProject.References.AddProject(secondProject)
End Sub
Return to top
Show: