Share via


Reference, interface

Cet objet représente une référence du projet. Le fait d'inclure une référence dans un projet vous permet d'utiliser tout membre public qu'elle contient. Les projets peuvent inclure des références à d'autres projets ou assemblys .NET et à des objets COM.

Espace de noms: VSLangProj
Assembly : VSLangProj (dans vslangproj.dll)

Syntaxe

'Déclaration
<GuidAttribute("35D6FB50-35B6-4C81-B91C-3930B0D95386")> _
Public Interface Reference
'Utilisation
Dim instance As Reference
[GuidAttribute("35D6FB50-35B6-4C81-B91C-3930B0D95386")] 
public interface Reference
[GuidAttribute(L"35D6FB50-35B6-4C81-B91C-3930B0D95386")] 
public interface class Reference
/** @attribute GuidAttribute("35D6FB50-35B6-4C81-B91C-3930B0D95386") */ 
public interface Reference
GuidAttribute("35D6FB50-35B6-4C81-B91C-3930B0D95386") 
public interface Reference

Notes

Les objets Reference sont contenus dans la collection References de l'objet VSProject. Les objets Reference sont de deux types : assemblys (y compris les projets Visual Studio .NET) et objets COM. Une référence à un autre projet (appelée « référence projet-à-projet ») reste considérée comme une référence d'assembly.

Exemple

L'exemple suivant crée un nouveau projet à partir d'un modèle, ajoute deux références et affiche leurs types.

'Macro Editor
Imports VSLangProj
Sub NewProject()
   Dim newName As String = InputBox("New project name:")
   ' Create a new project in the solution based on an existing
   ' project.
   Dim newProject As Project = DTE.Solution.AddFromTemplate( _
      "C:\TemplatePath\Template.vbproj", _
      "C:\ProjectPath\" & newName, newName)
        
   ' Add a COM reference and display its type.
   Dim vsProject As VSProject = CType(newProject.Object, VSProject)
   Dim newRef As Reference
   newRef = vsProject.References.Add("C:\WINNT\System32\msmask32.ocx")
   MsgBox(GetRefTypeName(newRef))
        
   ' Add an Assembly reference and display its type, "Assembly".
   newRef = vsProject.References.Add("C:\SomeProject\bin\SomeProject.dll")
   MsgBox(GetRefTypeName(newRef))
End Sub

Private Function GetRefTypeName(ByVal ref As Reference) _
   As String
   Dim type As String
   Select Case ref.Type
      Case prjReferenceType.prjReferenceTypeActiveX
         type = "COM"
      Case prjReferenceType.prjReferenceTypeAssembly
         type = "Assembly"
   End Select
   Return type
End Function

L'exemple suivant crée un court rapport des propriétés d'une référence.

' Macro Editor
' Create a small report about a reference.
Imports VSLangProj
Function ReportReferences(ByVal aRef As Reference) As String
   Dim report As String = ""
   Dim type As String
   ' Each entry in the ArrayList will contain a label and a value.
   Dim ht As System.Collections.ArrayList = _
      New System.Collections.ArrayList()
   With aRef
      ht.Add(New String() {"Name", .Name})
      ht.Add(New String() {"Description", .Description})
      ht.Add(New String() {"Version", String.Format("{0}.{1}.{2}.{3}", _
         .MajorVersion, .MinorVersion, .BuildNumber, .RevisionNumber)})
      ht.Add(New String() {"Location", .ContainingProject.FullName})
      Select Case .Type
         Case prjReferenceType.prjReferenceTypeActiveX
            type = "COM"
         Case prjReferenceType.prjReferenceTypeAssembly
            type = "Assembly"
      End Select
      ht.Add(New String() {"Type", type})
      ht.Add(New String() {"Culture", .Culture})
   End With
        
   Dim datas() As String
   For Each datas In ht
      report &= datas(0) & ControlChars.Tab & datas(1) & ControlChars.CrLf
   Next
   Return report
End Function

Voir aussi

Référence

Membres Reference
VSLangProj, espace de noms