次の方法で共有


Reference3.DTE Property

Definition

Gets the top-level extensibility object.

public:
 property EnvDTE::DTE ^ DTE { EnvDTE::DTE ^ get(); };
public:
 property EnvDTE::DTE ^ DTE { EnvDTE::DTE ^ get(); };
[System.Runtime.InteropServices.DispId(1)]
public EnvDTE.DTE DTE { [System.Runtime.InteropServices.DispId(1)] get; }
[<System.Runtime.InteropServices.DispId(1)>]
[<get: System.Runtime.InteropServices.DispId(1)>]
member this.DTE : EnvDTE.DTE
Public ReadOnly Property DTE As DTE

Property Value

DTE

A DTE object.

Implements

DTE
Attributes

Examples

This example demonstrates how to reach the DTE object from a Reference3 object. Open a Visual Basic or Visual C# project before running this example. To run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples.

The default path for the reference added (adodb.dll) in: <installation root>\Program Files\Microsoft.NET\Primary Interop Assemblies. Replace <file path> in the example with this or another appropriate 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());  
}  

Remarks

In Visual Studio, the DTE object is the root of the automation model, which other object models often call "Application".

Applies to