共用方式為


Reference3 介面

擴充 VSLangProj2 命名空間的 Reference2 介面。

命名空間:  VSLangProj80
組件:  VSLangProj80 (在 VSLangProj80.dll 中)

語法

'宣告
<GuidAttribute("5021602E-2025-4299-88D2-0A92E8B41ADF")> _
Public Interface Reference3 _
    Inherits Reference2
[GuidAttribute("5021602E-2025-4299-88D2-0A92E8B41ADF")]
public interface Reference3 : Reference2
[GuidAttribute(L"5021602E-2025-4299-88D2-0A92E8B41ADF")]
public interface class Reference3 : Reference2
[<GuidAttribute("5021602E-2025-4299-88D2-0A92E8B41ADF")>]
type Reference3 =  
    interface
        interface Reference2
    end
public interface Reference3 extends Reference2

Reference3 型別會公開下列成員。

屬性

  名稱 說明
公用屬性 Aliases 取得或設定指定參考的別名。此屬性僅套用至 Visual C#。
公用屬性 AutoReferenced 取得編譯器 (Compiler) 是否會自動參考此參考。
公用屬性 BuildNumber (繼承自 Reference2)。
公用屬性 BuildNumber 取得參考的組建編號。
公用屬性 Collection (繼承自 Reference2)。
公用屬性 Collection 取得 References 的集合。
公用屬性 ContainingProject (繼承自 Reference2)。
公用屬性 ContainingProject 取得含有此參考的 Project
公用屬性 CopyLocal (繼承自 Reference2)。
公用屬性 CopyLocal 取得或設定是否複製參考至本機的 bin 路徑。
公用屬性 Culture (繼承自 Reference2)。
公用屬性 Culture 取得參考的文化特性字串。
公用屬性 Description (繼承自 Reference2)。
公用屬性 Description 取得參考的文字描述。
公用屬性 DTE (繼承自 Reference2)。
公用屬性 DTE 取得最上層的擴充性物件。
公用屬性 Extender[String] (繼承自 Reference2)。
公用屬性 Extender[String] 基礎架構。僅限 Microsoft 內部使用。
公用屬性 ExtenderCATID (繼承自 Reference2)。
公用屬性 ExtenderCATID 基礎架構。僅限 Microsoft 內部使用。
公用屬性 ExtenderNames (繼承自 Reference2)。
公用屬性 ExtenderNames 基礎架構。僅限 Microsoft 內部使用。
公用屬性 Identity (繼承自 Reference2)。
公用屬性 Identity 取得參考的唯一識別項。
公用屬性 Isolated 取得或設定是否隔離 COM 參考,也就是說不向 Windows 註冊。
公用屬性 MajorVersion (繼承自 Reference2)。
公用屬性 MajorVersion 取得參考的主要版本號碼。
公用屬性 MinorVersion (繼承自 Reference2)。
公用屬性 MinorVersion 取得參考的次要版本號碼。
公用屬性 Name (繼承自 Reference2)。
公用屬性 Name 取得物件的名稱。
公用屬性 Path (繼承自 Reference2)。
公用屬性 Path 取得參考檔的路徑。
公用屬性 PublicKeyToken (繼承自 Reference2)。
公用屬性 PublicKeyToken 從強式簽名的參考取得公開金鑰 (Public Key) 語彙基元。
公用屬性 RefType 取得參考型別:組件、COM 或原生 (Native)。
公用屬性 Resolved 取得是否已解析目前的參考。
公用屬性 RevisionNumber (繼承自 Reference2)。
公用屬性 RevisionNumber 取得參考的修訂編號。
公用屬性 RuntimeVersion (繼承自 Reference2)。
公用屬性 RuntimeVersion 取得參考所據以建置的執行階段版本。這僅適用於 .NET 參考。
公用屬性 SourceProject (繼承自 Reference2)。
公用屬性 SourceProject 如果參考是專案,則會取得 Project 物件。否則,會傳回 Nothing (null 物件)。
公用屬性 SpecificVersion 取得或設定是否僅使用特定版本的參考。
公用屬性 StrongName (繼承自 Reference2)。
公用屬性 StrongName 取得參考是否已用公開/私密金鑰組 (Key Pair) 加上簽章。
公用屬性 SubType 設定或取得組件子型別。
公用屬性 Type (繼承自 Reference2)。
公用屬性 Type 已過時。只適用於處理回溯相容性 (Backward Compatibility)。請改用 RefType
公用屬性 Version (繼承自 Reference2)。
公用屬性 Version 取得指定參考的版本。

回頁首

方法

  名稱 說明
公用方法 Remove() (繼承自 Reference2)。
公用方法 Remove() 從包含參考的 References 物件中移除參考。

回頁首

備註

Reference3 會定義下列的新參數:

Aliases

AutoReferenced

Isolated

RefType

SpecificVersion

範例

下列範例會將兩個參考加入至開啟的 Visual Basic 或 Visual C# 專案, 然後會呼叫 GetRefTypeName 函數以顯示參考型別 (Reference Type),並呼叫 ReportReferences 函數以顯示其他參考屬性。 若要將此範例當做增益集來執行,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例

新增的參考之預設路徑:adodb.dll 為 <installation root>\Program Files\Microsoft.NET\Primary Interop Assemblies,以及 spcommon.dll 為 <installation root>\Program Files\Common Files\SpeechEngines\Microsoft。 以這兩個或其他適當的檔案路徑取代範例中的 <file path>。

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;
}

請參閱

參考

VSLangProj80 命名空間

Reference