Compartilhar via


SolutionFolder.AddFromFile(String) Method

Definition

Adds an existing project to the solution folder.

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

Parameters

FileName
String

The full path of the project.

Returns

A Project object.

Attributes

Examples

This example creates a new solution folder and adds a project to it from an existing file. 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 solnFolderAddFromFileExample(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.")  
    Catch ex As System.Exception  
        MsgBox(ex.ToString)  
    End Try  
End Sub  
using EnvDTE;  
using EnvDTE80;  
using System.Windows.Forms;  
public void solnFolderAddFromFileExample(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.");  
    }  
    catch(SystemException ex)  
    {  
        MessageBox.Show(ex.ToString());  
    }  
}  

Applies to