共用方式為


Reference 介面

表示專案中的一個參考。 包含專案中的參考,讓您可以使用此參考中的任何公用成員。 專案可能包含對其他 .NET 專案、.NET 組件 (Assembly) 和 COM 物件的參考。

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

語法

'宣告
<GuidAttribute("35D6FB50-35B6-4C81-B91C-3930B0D95386")> _
Public Interface Reference
[GuidAttribute("35D6FB50-35B6-4C81-B91C-3930B0D95386")]
public interface Reference
[GuidAttribute(L"35D6FB50-35B6-4C81-B91C-3930B0D95386")]
public interface class Reference
[<GuidAttribute("35D6FB50-35B6-4C81-B91C-3930B0D95386")>]
type Reference =  interface end
public interface Reference

Reference 型別會公開下列成員。

屬性

  名稱 說明
公用屬性 BuildNumber 取得參考的組建編號。唯讀。
公用屬性 Collection 取得集合,內含支援這個屬性的物件或這個程式碼建構中的物件。
公用屬性 ContainingProject 取得選定項目所屬專案。唯讀。
公用屬性 CopyLocal 決定是否複製參考到本地的 bin 路徑。
公用屬性 Culture 取得參考的文化特性字串。唯讀。
公用屬性 Description 取得參考的文字描述。唯讀。
公用屬性 DTE 取得最上層的擴充性物件。
公用屬性 Extender 取得要求的擴充項物件 (如果適用於這個物件)。
公用屬性 ExtenderCATID 取得物件的擴充項分類 ID (CATID)。
公用屬性 ExtenderNames 取得物件的可用擴充項清單。
公用屬性 Identity 取得參考的唯一識別項。唯讀。
公用屬性 MajorVersion 取得參考的主要版本號碼。唯讀。
公用屬性 MinorVersion 取得參考的次要版本號碼。唯讀。
公用屬性 Name 取得物件的名稱。唯讀。
公用屬性 Path 取得參考檔的路徑。唯讀。
公用屬性 PublicKeyToken 取得所參考組件的公開金鑰語彙基元。
公用屬性 RevisionNumber 取得參考的修訂編號。唯讀。
公用屬性 SourceProject 如果參考是專案,則會取得 Project 物件。否則會傳回 Nothing (nullNull 參照 (即 Visual Basic 中的 Nothing) 參考)。唯讀。
公用屬性 StrongName 取得參考是否已用公開/私密金鑰組 (Key Pair) 加上簽章。唯讀。
公用屬性 Type 取得 prjReferenceType 值,表示參考為組件或 COM 元件。唯讀。
公用屬性 Version 取得選定參考的版本。

回頁首

方法

  名稱 說明
公用方法 Remove 從包含參考的 References 物件中取得參考。

回頁首

備註

Reference 物件包含在 VSProject 物件的 References 集合中。 共有兩種類型的 Reference 物件:組件 (包含 Visual Studio 專案) 和 COM 物件。 當參考是其他專案時,稱為專案對專案的參考,且仍視為組件參考。

範例

下列範例將利用樣板建立新的專案、新增兩個參考並顯示它們的類型。

'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

下列範例將建立參考屬性 (Property) 的簡式報表。

' 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

請參閱

參考

VSLangProj 命名空間