Solution2.AddFromFile(String, Boolean) Method

Definition

Adds a project to the solution that is based on a project file already stored in the system.

EnvDTE::Project AddFromFile(std::wstring const & FileName, bool Exclusive = false);
[System.Runtime.InteropServices.DispId(16)]
public EnvDTE.Project AddFromFile (string FileName, bool Exclusive = false);
[<System.Runtime.InteropServices.DispId(16)>]
abstract member AddFromFile : string * bool -> EnvDTE.Project
Public Function AddFromFile (FileName As String, Optional Exclusive As Boolean = false) As Project

Parameters

FileName
String

Required. The full path and file name of the project file.

Exclusive
Boolean

Optional. Indicates whether the project loads in the current solution or its own solution; true if the current solution is closed and the project is added to a new solution, false if the project is added to the existing, open solution.

Returns

A Project object.

Implements

Attributes

Examples

Sub AddFromFileExample(ByVal dte As DTE2)  
    ' Ceates a solution and adds an existing project to it.  
    Try  
        Dim soln As Solution2 =  _  
        CType(_applicationObject.Solution, Solution2)  
        ' Create a new solution.  
        ' Make sure the path below exists on your computer.  
        ' You can modify the path.  
        soln.Create("c:\temp2", "MyNewSolution")  
        ' Add an existing project to the new solution.  
        ' Modify the path to a location that contains a  
        ' Visual Studio project.  
        soln.AddFromFile _  
        ' Make sure to set the path below to the default project location on your computer  
        ("c:\temp1\Visual Studio 2010\ _    
        Projects\ConsoleApplication\ConsoleApplication\ _  
        ConsoleApplication.csproj")  
    Catch ex As System.Exception  
        MsgBox(ex.ToString)  
    End Try  
End Sub  
public void AddFromFileExample(DTE2 dte)  
{  
    // Creates a solution and adds an existing project to it.   
    try  
    {  
        Solution2 soln = (Solution2)_applicationObject.Solution;  
        // Create a solution.  
        // Make sure that the file path specified below  
        // exists on your computer.  
        // You can modify the path.  
        soln.Create("c:\temp2", "MyNewSolution");  
        // Add an existing project to the new solution.  
        // Modify the path to a location that contains  
        // a Visual Studio project.  
        soln.AddFromFile("c:\temp1"  
\Visual Studio 2010\Projects\ConsoleApplication  
\ConsoleApplication\ ConsoleApplication.csproj", true);  
        }  
    catch(SystemException ex)  
    {  
        MessageBox.Show("ERROR: " + ex);  
    }  
}  

Remarks

You can use the LaunchWizard method rather than AddFromFile to execute a wizard if you want to suppress its user interface (UI) during execution. LaunchWizard has a parameter that allows you to disable the UI.

Applies to