Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library

Reference Interface

Represents one reference in the project. Including a reference in a project allows you to use any of the public members contained in the reference. Projects may include references to other .NET projects, .NET assemblies, and COM objects.

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

public interface Reference

The Reference type exposes the following members.

Public propertyBuildNumberGets the build number of the reference. Read-only.
Public propertyCollectionGets the collection containing the object supporting this property or contained within this code construct.
Public propertyContainingProjectGets the project that the selected item is a part of. Read-only.
Public propertyCopyLocalDetermines whether the reference is copied to the local bin path.
Public propertyCultureGets the culture string of a reference. Read-only.
Public propertyDescriptionGets a text description of the reference. Read-only.
Public propertyDTEGets the top-level extensibility object.
Public propertyExtenderGets the requested Extender object if it is available for this object.
Public propertyExtenderCATIDGets the Extender category ID (CATID) for the object.
Public propertyExtenderNamesGets a list of available Extenders for the object.
Public propertyIdentityGets the unique identifier of the reference. Read-only.
Public propertyMajorVersionGets the major version number of the reference. Read-only.
Public propertyMinorVersionGets the minor version number of the reference. Read-only.
Public propertyNameGets the name of the object. Read-only.
Public propertyPathGets the path to the reference file. Read-only.
Public propertyPublicKeyTokenGets the public key token for the referenced assembly.
Public propertyRevisionNumberGets the revision number of the reference. Read-only.
Public propertySourceProjectGets a Project object if the reference is a project. Otherwise, it returns Nothing (a null reference). Read-only.
Public propertyStrongNameGets whether the reference is signed with a public/private key pair. Read-only.
Public propertyTypeGets a prjReferenceType value indicating whether the reference is an assembly or a COM component. Read-only.
Public propertyVersionGets the version of the selected reference.

Public methodRemoveGets the reference from the References object that contains it.

Reference objects are contained in the VSProject object's References collection. There are two types of Reference objects: assemblies (including Visual Studio projects) and COM objects. When a reference is another project, this is called a project-to-project reference and is still considered an assembly reference.

The following example creates a new project from a template, adds two references, and displays their 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")
   ' Add an Assembly reference and display its type, "Assembly".
   newRef = vsProject.References.Add("C:\SomeProject\bin\SomeProject.dll")
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

The following example creates a short report of a reference's properties.

' 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
   Return report
End Function
© 2015 Microsoft