Reference 接口
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示项目中的一个引用。 通过在项目中包含引用,可以使用引用中包含的任何公共成员。 项目可能包括对其他 .NET 项目、.NET 程序集和 COM 对象的引用。
public interface class Reference
public interface class Reference
__interface Reference
[System.Runtime.InteropServices.Guid("35D6FB50-35B6-4C81-B91C-3930B0D95386")]
[System.Runtime.InteropServices.TypeLibType(4160)]
public interface Reference
[<System.Runtime.InteropServices.Guid("35D6FB50-35B6-4C81-B91C-3930B0D95386")>]
[<System.Runtime.InteropServices.TypeLibType(4160)>]
type Reference = interface
Public Interface Reference
- 派生
- 属性
示例
下面的示例从模板创建一个新项目,添加两个引用并显示其类型。
'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
下面的示例创建一个引用属性的简短报表。
' 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
注解
Reference 对象包含在 VSProject 对象的集合中 References 。 有两种类型的 Reference 对象:程序集 (包括 Visual Studio 项目) 和 COM 对象。 当引用是另一个项目时,这称为项目到项目的引用,并且仍被视为程序集引用。
属性
| BuildNumber |
获取引用的生成号。 只读。 |
| Collection |
获取包含某个对象的集合,该对象支持此属性或包含在此代码构造中。 |
| ContainingProject |
获取选定项所属的项目。 只读。 |
| CopyLocal |
确定是否将引用复制到本地 bin 路径。 |
| Culture |
获取引用的区域性字符串。 只读。 |
| Description |
获取引用的文本说明。 只读。 |
| DTE |
获取顶级扩展性对象。 |
| Extender[String] |
获取请求的扩展程序对象(如果对此对象可用)。 |
| ExtenderCATID |
获取对象的扩展程序类别 ID (CATID)。 |
| ExtenderNames |
获取对象的可用扩展程序的列表。 |
| Identity |
获取引用的唯一标识符。 只读。 |
| MajorVersion |
获取引用的主版本号。 只读。 |
| MinorVersion |
获取引用的次版本号。 只读。 |
| Name |
获取对象的名称。 只读。 |
| Path |
获取引用文件的路径。 只读。 |
| PublicKeyToken |
获取已引用程序集的公钥标记。 |
| RevisionNumber |
获取引用的修订号。 只读。 |
| SourceProject |
如果引用是项目,则获取项目对象。 否则,将不 (空引用) 返回任何内容。 只读。 |
| StrongName |
获取是否已使用公钥/私钥对对引用进行签名。 只读。 |
| Type |
获取一个 prjReferenceType 值,该值指示引用是否为程序集或 COM 组件。 只读。 |
| Version |
获取所选引用的版本。 |
方法
| Remove() |
获取 References 包含它的对象的引用。 |