VSProject2.References 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取 References 项目的集合。
public:
property VSLangProj::References ^ References { VSLangProj::References ^ get(); };
[System.Runtime.InteropServices.DispId(1)]
public VSLangProj.References References { [System.Runtime.InteropServices.DispId(1)] get; }
[<System.Runtime.InteropServices.DispId(1)>]
[<get: System.Runtime.InteropServices.DispId(1)>]
member this.References : VSLangProj.References
Public ReadOnly Property References As References
属性值
一个 References 包含对象的集合 Reference ,每个对象表示一个引用。
实现
- 属性
示例
若要将此示例作为外接程序运行,请参阅 如何:编译和运行自动化对象模型代码示例。 此示例假设解决方案中的第一个项目是 Visual Basic 或 Visual C# 项目。
[Visual Basic]
' Add-in.
' Assuming that the first project in the solution is a Visual Basic
' or C# application, this routine lists the references
' in the project.
Imports VSLangProj
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)
ListReferences(applicationObject)
End Sub
Sub ListReferences(ByVal dte As DTE2)
' Retrieve the VSProject2 object.
Dim theVSProject As VSProject2 = _
CType(applicationObject.Solution.Projects.Item(1).Object, _
VSProject2)
' Retrieve the references collection.
Dim refs As References = theVSProject.References
' Create a string list of the reference names.
Dim refList As String = ""
Dim aRef As Reference3
For Each aRef In refs
refList &= aRef.Identity & ControlChars.CrLf
Next
MsgBox(refList)
End Sub
[C#]
// Add-in.
// Assuming that the first project in the solution is a Visual Basic
// or C# application, this routine lists the references
// in the project.
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;
ListReferences((DTE2)applicationObject);
}
public void ListReferences( DTE2 dte )
{
// Retrieve the VSProject2 object.
VSProject2 theVSProject = ( ( VSProject2 )
(applicationObject.Solution.Projects.Item( 1 ).Object ) );
// Retrieve the references collection.
References refs = theVSProject.References;
// Create a string list of the reference names.
string refList = "";
Reference3 aRef = null;
foreach ( VSLangProj80.Reference3 temp in refs )
{
aRef = temp;
refList += aRef.Identity + "\n";
}
MessageBox.Show( refList);
}
注解
若要针对外部组件编写代码,你的项目必须首先包含对该组件的引用。 可对三种类型的组件进行引用: .NET 程序集、COM 自动化服务器和控件,以及在公开组件的同一解决方案中的其他项目。