Share via


Reference3 Interface

Definition

Extends the Reference2 interface of the VSLangProj2 namespace.

public interface class Reference3 : VSLangProj2::Reference2
public interface class Reference3 : VSLangProj2::Reference2
__interface Reference3 : VSLangProj2::Reference2
[System.Runtime.InteropServices.Guid("5021602E-2025-4299-88D2-0A92E8B41ADF")]
[System.Runtime.InteropServices.TypeLibType(4160)]
public interface Reference3 : VSLangProj2.Reference2
[System.Runtime.InteropServices.Guid("5021602E-2025-4299-88D2-0A92E8B41ADF")]
public interface Reference3 : VSLangProj2.Reference2
[<System.Runtime.InteropServices.Guid("5021602E-2025-4299-88D2-0A92E8B41ADF")>]
[<System.Runtime.InteropServices.TypeLibType(4160)>]
type Reference3 = interface
    interface Reference2
[<System.Runtime.InteropServices.Guid("5021602E-2025-4299-88D2-0A92E8B41ADF")>]
type Reference3 = interface
    interface Reference2
    interface Reference
Public Interface Reference3
Implements Reference2
Derived
Attributes
Implements

Examples

The following example adds two references to an open Visual Basic or Visual C# project. It then calls a function, GetRefTypeName, to display the reference type and calls a function, ReportReferences, to display additional reference properties. To run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples.

The default paths for the added references are : <installation root>\Program Files\Microsoft.NET\Primary Interop Assemblies for adodb.dll, and <installation root>\Program Files\Common Files\SpeechEngines\Microsoft for spcommon.dll. Replace the <file path> in the example with these or other appropriate file paths.

Imports VSLangProj  
Imports VSLangProj2  
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)  
    AddNewReference(applicationObject)  
End Sub  
Sub AddNewReference(ByVal dte As DTE2)  
    Dim aProject As Project  
    Dim aVSProject As VSProject2  
    aProject = applicationObject.Solution.Projects.Item(1)  
    aVSProject =_  
 CType(applicationObject.Solution.Projects.Item(1).Object, VSProject2)  
    ' Add an Assembly reference and display its type and additional  
    ' information.  
    Dim newRef As Reference3  
    ' Replace <file path> with an actual path.  
    newRef = aVSProject.References.Add("<file path>\adodb.dll")  
    MsgBox("The " & newRef.Name() & " added, is of type:" & vbCr _  
    & GetRefTypeName(newRef))  
    MsgBox("A report on " & newRef.Name() & ":" & vbCr & _  
    ReportReferences(newRef))  
    ' Add a COM reference and display its type and a report.  
    ' Replace <file path> with an actual path.  
    newRef = aVSProject.References.Add("<file path>\spcommon.dll")  
    MsgBox("The " & newRef.Name() & " added, is of type:" & vbCr _  
    & GetRefTypeName(newRef))  
    MsgBox("A report on " & newRef.Name() & ":" & vbCr & _  
    ReportReferences(newRef))  
End Sub  
Private Function GetRefTypeName(ByVal ref As Reference3) _  
    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  
Function ReportReferences(ByVal aRef As Reference3) As String  
    Dim report As String = ""  
    Dim type As String  
    ' Each entry in the ArrayList contains 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  
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;  
    AddNewReference(((DTE2)applicationObject));  
}  

public void AddNewReference(DTE2 dte)  
{  
    Project aProject = null;  
    VSProject2 aVSProject = null;  
    aProject = applicationObject.Solution.Projects.Item(1);  
    aVSProject =   
((VSProject2)(applicationObject.Solution.Projects.Item(1).Object));  
    // Add an Assembly reference and display its type and a report.  
    Reference3 newRef = null;  
    // Replace <file path> with an actual file path.  
    newRef = ((Reference3)(aVSProject.References.Add(@"  
<file path>\adodb.dll")));  
    MessageBox.Show("The " + newRef.Name + " added, is of type:"   
+ "\n" + GetRefTypeName(newRef));  
    MessageBox.Show("A report on " + newRef.Name + ":" + "\n"   
+ ReportReferences(newRef));   
    // Add a COM reference and display its type and a report.  
    // Replace <file path> with an actual file path.  
    newRef = ((Reference3)(aVSProject.References.Add(@"  
<file path>\spcommon.dll")));  
    MessageBox.Show("The " + newRef.Name + " added, is of type:"   
+ "\n" + GetRefTypeName(newRef));  
    MessageBox.Show("A report on " + newRef.Name + ":" + "\n"   
+ ReportReferences(newRef));   
}  
private string GetRefTypeName(Reference3 refIdent)  
{  
    string type = null;  
    switch (refIdent.Type)  
    {  
     case prjReferenceType.prjReferenceTypeActiveX:  
        type = "COM";  
        break;  
    case prjReferenceType.prjReferenceTypeAssembly:  
        type = "Assembly";  
        break;  
    }  
    return type;  
}  
public string ReportReferences(Reference3 aRef)  
{  
    string report = "";  
    string type = null;  
    // Each entry in the ArrayList contains a label and a value.  
    System.Collections.ArrayList ht =   
new System.Collections.ArrayList();  
    VSLangProj.Reference temp = aRef;  
    ht.Add(new string[] { "Name", temp.Name });  
    ht.Add(new string[] { "Description", temp.Description });  
   ht.Add(new string[] { "Version", string.Format("{0}.{1}.{2}.{3}"  
, temp.MajorVersion, temp.MinorVersion,   
temp.BuildNumber, temp.RevisionNumber) });  
    ht.Add(new string[] { "Location",   
temp.ContainingProject.FullName });  
    switch (temp.Type)  
    {  
        case prjReferenceType.prjReferenceTypeActiveX:  
            type = "COM";  
            break;  
        case prjReferenceType.prjReferenceTypeAssembly:  
            type = "Assembly";  
            break;  
    }  
    ht.Add(new string[] { "Type", type });  
    ht.Add(new string[] { "Culture", temp.Culture });  
    string[] datas = null;  
    foreach (string[] temp1 in ht)  
    {  
        datas = temp1;   
        report += datas[0] + "\t" + datas[1] + "\n";  
    }  
    return report;  
}  

Remarks

Reference3 defines the following new parameters:

Aliases

AutoReferenced

Isolated

RefType

SpecificVersion

Properties

Aliases

Gets or sets the aliased names for the specified reference. This property applies to Visual C# only.

AutoReferenced

Gets whether the reference is automatically referenced by the compiler.

BuildNumber

Gets the build number of the reference.

Collection

Gets a collection of References.

ContainingProject

Gets the Project containing the reference.

CopyLocal

Gets or sets whether the reference is copied to the local bin path.

Culture

Gets the culture string of a reference.

Description

Gets a text description of the reference.

DTE

Gets the top-level extensibility object.

Extender[String]

Microsoft Internal Use Only.

ExtenderCATID

Microsoft Internal Use Only.

ExtenderNames

Microsoft Internal Use Only.

Identity

Gets the unique identifier of the reference.

Isolated

Gets or sets whether the COM reference is isolated, that is, not registered with Windows.

MajorVersion

Gets the major version number of the reference.

MinorVersion

Gets the minor version number of the reference.

Name

Gets the name of the object.

Path

Gets the path to the reference file.

PublicKeyToken

Gets the public key token from a strongly signed reference.

RefType

Gets the type of reference: assembly, COM, or native.

Resolved

Gets whether the current reference was resolved.

RevisionNumber

Gets the revision number of the reference.

RuntimeVersion

Gets the version of the runtime against which the reference was built. This is applicable only for .NET references.

SourceProject

Gets a Project object if the reference is a project. Otherwise, it returns Nothing (a null object).

SpecificVersion

Gets or sets whether only a specific version of the reference is used.

StrongName

Gets whether the reference is signed with a public/private key pair.

SubType

Sets or Gets the assembly subtype.

Type

Obsolete. Included for backward compatibility only. Use RefType instead.

Version

Gets the version of the specified reference.

Methods

get_Extender(String)
Remove()

Removes the reference from the References object that contains it.

Applies to