Reference3.DTE 属性

获取顶级扩展性对象。

命名空间:  VSLangProj80
程序集:  VSLangProj80(在 VSLangProj80.dll 中)

语法

声明
ReadOnly Property DTE As DTE
DTE DTE { get; }
property DTE^ DTE {
    DTE^ get ();
}
abstract DTE : DTE
function get DTE () : DTE

属性值

类型:EnvDTE.DTE
一个 DTE 对象。

备注

在 Visual Studio 中,DTE 对象是自动化模型的根,其他对象模型常常称之为“应用程序”。

示例

此示例演示如何从 Reference3 对象到达 DTE 对象。在运行此示例之前,请打开一个 Visual Basic 或 Visual C# 项目。若要将此示例作为外接程序运行,请参见如何:编译和运行自动化对象模型代码示例

所添加的引用 (adodb.dll) 的默认路径为:<安装根目录>\Program Files\Microsoft.NET\Primary Interop Assemblies。请将示例中的 <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)
    ReachDTEObject(applicationObject)
End Sub
Public Sub ReachDTEObject(ByVal dte As DTE2)
    ' The first project is a Visual Basic or C# project.
    Dim vsProject As VSProject2 = _
    CType(applicationObject.Solution.Projects.Item(1).Object, _
    VSProject2)
    Dim aRef As Reference3
    ' Replace the <file path> with an actual file path.
    aRef = CType(vsProject.References.Add_
    ("<file path>\adodb.dll"), Reference3)
    MsgBox("Added a reference named: " & aRef.Name.ToString())
    MsgBox("Name of the containing solution for " & aRef.Name & _
    vbCr & "reached through the DTE object is: " & vbCr & _
    aRef.DTE.Solution.FullName.ToString())
End Sub
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;
    ReachDTEObject(((DTE2)applicationObject));
}
public void ReachDTEObject(DTE2 dte)
{
    // The first project is a Visual Basic or C# project.
    VSProject2 vsProject = 
((VSProject2)(applicationObject.Solution.Projects.Item(1).Object));
    Reference3 aRef = null;
    // Replace <file path> with an actual file path.
    aRef = (Reference3)vsProject.References.Add
((@"<file path>\adodb.dll"));
    MessageBox.Show ("Added a reference named: " 
+ aRef.Name.ToString());
    MessageBox.Show("Name of the containing solution for " 
+ aRef.Name + "\n" + "reached through the DTE object is: " + "\n" 
+ aRef.DTE.Solution.FullName.ToString());
}

.NET Framework 安全性

请参见

参考

Reference3 接口

DTE 重载

VSLangProj80 命名空间