References.AddProject(Project) Method


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

 VSLangProj::Reference ^ AddProject(EnvDTE::Project ^ pProject);
 VSLangProj::Reference ^ AddProject(EnvDTE::Project ^ pProject);
VSLangProj::Reference AddProject(EnvDTE::Project const & pProject);
public VSLangProj.Reference AddProject (EnvDTE.Project pProject);
abstract member AddProject : EnvDTE.Project -> VSLangProj.Reference
Public Function AddProject (pProject As Project) As Reference



Required. The Project object to be added.




' 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  


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.

Applies to