Condividi tramite


Proprietà VSProject2.References

Ottiene l'insieme References per il progetto.

Spazio dei nomi:  VSLangProj80
Assembly:  VSLangProj80 (in VSLangProj80.dll)

Sintassi

'Dichiarazione
ReadOnly Property References As References
    Get
References References { get; }
property References^ References {
    References^ get ();
}
abstract References : References
function get References () : References

Valore proprietà

Tipo: VSLangProj.References
Insieme References che contiene oggetti Reference, ciascuno rappresentante un riferimento.

Implementa

VSProject.References

Note

Prima di creare codice in base a un componente esterno, è necessario che il progetto contenga un riferimento a tale componente. È possibile fare riferimento a tre tipi di componenti: assembly .NET, server e controlli di automazione COM nonché altri progetti all'interno della stessa soluzione che espongono componenti.

Esempi

Per eseguire questo esempio come componente aggiuntivo, vedere Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione. Nell'esempio riportato di seguito si presuppone che il primo progetto della soluzione sia un progetto di Visual Basic o Visual C#.

[Visual Basic]

' Add-in.
' Assuming that the first project in the solution is a Visual Basic 
' or C# application, this routine lists the references 
' in the project.
Imports VSLangProj
Imports VSLangProj80
Public Sub OnConnection(ByVal application As Object_
, ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    applicationObject = CType(application, DTE2)
    addInInstance = CType(addInInst, AddIn)
    ListReferences(applicationObject)
End Sub

Sub ListReferences(ByVal dte As DTE2)
    ' Retrieve the VSProject2 object.
    Dim theVSProject As VSProject2 = _
    CType(applicationObject.Solution.Projects.Item(1).Object, _
    VSProject2)
    ' Retrieve the references collection.
    Dim refs As References = theVSProject.References

    ' Create a string list of the reference names.
    Dim refList As String = ""
    Dim aRef As Reference3
    For Each aRef In refs
        refList &= aRef.Identity & ControlChars.CrLf
    Next
    MsgBox(refList)
End Sub

[C#]

// Add-in.
// Assuming that the first project in the solution is a Visual Basic 
// or C# application, this routine lists the references 
// in the project.
using System.Windows.Forms;
using VSLangProj;
using VSLangProj2;
using VSLangProj80;

public void OnConnection(object application, ext_ConnectMode
 connectMode, object addInInst, ref Array custom)
{
    applicationObject = (DTE2)application;
    addInInstance = (AddIn)addInInst;
    ListReferences((DTE2)applicationObject);
}

public void ListReferences( DTE2 dte ) 
{ 
    // Retrieve the VSProject2 object.
    VSProject2 theVSProject = ( ( VSProject2 )
(applicationObject.Solution.Projects.Item( 1 ).Object ) ); 
    // Retrieve the references collection.
    References refs = theVSProject.References; 
            
    // Create a string list of the reference names.
    string refList = ""; 
    Reference3 aRef = null; 
    foreach ( VSLangProj80.Reference3 temp in refs ) 
    { 
        aRef = temp; 
        refList += aRef.Identity + "\n"; 
    }
    MessageBox.Show( refList); 
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

VSProject2 Interfaccia

Overload References

Spazio dei nomi VSLangProj80

References