Share via


VCProject.AddProjectReference Method

Adds a project reference to the project.

Namespace:  Microsoft.VisualStudio.VCProjectEngine
Assembly:  Microsoft.VisualStudio.VCProjectEngine (in Microsoft.VisualStudio.VCProjectEngine.dll)

Syntax

'Declaration
Function AddProjectReference ( _
    proj As Object _
) As Object
Object AddProjectReference(
    Object proj
)
Object^ AddProjectReference(
    [InAttribute] Object^ proj
)
abstract AddProjectReference : 
        proj:Object -> Object
function AddProjectReference(
    proj : Object
) : Object

Parameters

  • proj
    Type: Object

    The project reference to add.

Return Value

Type: Object
An object representing the project reference.

Remarks

You can reference only loaded projects.

Examples

See How to: Compile Example Code for Project Model Extensibility for information about how to compile and run this example.

AddProjectReference adds a second project as a reference to the first project, if possible.

' Add a reference to Microsoft.VisualStudio.VCProjectEngine and have 
' two Visual C++ projects loaded before running this example.
Imports EnvDTE
Imports Microsoft.VisualStudio.VCProjectEngine
Public Module Module1
    Sub Test()
        Dim prj1, prj2 As VCProject
        prj1 = DTE.Solution.Projects.Item(1).Object
        prj2 = DTE.Solution.Projects.Item(2).Object
        ' Adds project 2 as a reference to project 1.
        If prj1.CanAddProjectReference(prj2) Then
            prj1.AddProjectReference(prj2)
        End If
    End Sub
End Module

.NET Framework Security

See Also

Reference

VCProject Interface

Microsoft.VisualStudio.VCProjectEngine Namespace