Partager via


SolutionFolder.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.

Attributes

Examples

This example creates a new solution folder and adds a project to it from an existing file. It then uses a message box to display the caption of the main window, obtained through the DTE object. Before running this example, create a "Projects" folder off your main drive ("C:" in this example), and create a Visual C# class library project, named "ClassLibrary1" in that folder. You need to also open a project in the Visual Studio integrated development environment (IDE) before running this example.

Imports EnvDTE  
Imports EnvDTE80  
Sub solnFolderDTEExample(ByVal dte As DTE2)  
    ' Before running this example, create a "Projects" folder  
    ' off your main drive (C: in this example), and create a C#   
    ' class library project, named ClassLibrary1 in that folder.  
    Dim soln As Solution2 = CType(_applicationObject.Solution _  
    , Solution2)  
    Dim prj As Project  
    Dim SF As SolutionFolder  
    Try  
        Dim prjPath As String = _  
        "C:\Projects\ClassLibrary1\ClassLibrary1\ClassLibrary1.csproj"  
        ' Open a project in the Visual Studio IDE before   
        ' running this example.  
        ' Add a solution folder.  
        prj = soln.AddSolutionFolder("A new soln folder")  
        SF = CType(prj.Object, SolutionFolder)  
        ' Add a project to the new solution folder.  
        SF.AddFromFile(prjPath)  
        MsgBox("Added a new solution folder that contains a  _  
        C# project named ClassLibrary1.")  
        MsgBox("The main window caption, obtained through the  _  
        DTE object is: " & SF.DTE.MainWindow.Caption)  
    Catch ex As System.Exception  
        MsgBox(ex.ToString)  
    End Try  
End Sub  
using EnvDTE;  
using EnvDTE80;  
using System.Windows.Forms;  
public void solnFolderDTEExample(DTE2 dte)  
{  
    // Before running this example, create a "Projects" folder  
    // off your main drive (C: in this example), and create a C#   
    // class library project, named ClassLibrary1 in that folder.  
    Solution2 soln = (Solution2)_applicationObject.Solution;  
    Project prj;  
    SolutionFolder SF;  
    try  
    {  
        String prjPath =   
"C:\\Projects\\ClassLibrary1\\ClassLibrary1\\ClassLibrary1.csproj";  
        // Open a project in the Visual Studio IDE before running   
        // this example.  
        // Add a solution folder.  
        prj = soln.AddSolutionFolder("A new soln folder");  
        SF = (SolutionFolder)prj.Object;  
        // Add a project to the new solution folder.  
        SF.AddFromFile(prjPath);  
        MessageBox.Show("Added a new solution folder that contains a   
C# project named ClassLibrary1.");  
        MessageBox.Show("The main window caption, obtained through   
the DTE object is: " + SF.DTE.MainWindow.Caption);  

    catch(SystemException ex)  
    {  
        MessageBox.Show(ex.ToString());  
    }  
}  

Remarks

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

Applies to