共用方式為


SolutionFolder.AddSolutionFolder(String) Method

Definition

Adds a solution folder to a ProjectItems collection.

public:
 EnvDTE::Project ^ AddSolutionFolder(System::String ^ Name);
public:
 EnvDTE::Project ^ AddSolutionFolder(Platform::String ^ Name);
EnvDTE::Project AddSolutionFolder(std::wstring const & Name);
[System.Runtime.InteropServices.DispId(3)]
public EnvDTE.Project AddSolutionFolder (string Name);
[<System.Runtime.InteropServices.DispId(3)>]
abstract member AddSolutionFolder : string -> EnvDTE.Project
Public Function AddSolutionFolder (Name As String) As Project

Parameters

Name
String

The name of the solution folder.

Returns

A Project object.

Attributes

Examples

This example creates a new solution folder and adds a project to it from an existing file. It also adds a new nested solution folder to the first one by using the AddSolutionFolder method. 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. Open a project in the Visual Studio integrated development environment (IDE) before running this example.

Imports EnvDTE  
Imports EnvDTE80  
Sub solnFolderAddSolutionFolderExample(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 sb As New System.Text.StringBuilder  
    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.")  
        SF.AddSolutionFolder("New solnFolder2")  
        MsgBox("Added a new solution folder, called 'New solnFolder2'.")  
    Catch ex As System.Exception  
        MsgBox(ex.ToString)  
    End Try  
End Sub  
using EnvDTE;  
using EnvDTE80;  
using System.Windows.Forms;  
public void solnFolderAddSolutionFolderExample(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;  
    System.Text.StringBuilder sb = new System.Text.StringBuilder();  
    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.");  
        SF.AddSolutionFolder("New solnFolder2");  
        MessageBox.Show("Added a new solution folder,   
called 'New solnFolder2'.");  
    }  
    catch(SystemException ex)  
    {  
        MessageBox.Show(ex.ToString());  
    }  
}  

Remarks

AddSolutionFolder returns a Project object that you can be cast or query interface (QI) to a SolutionFolder object.

Applies to