Freigeben über


_Solution.AddFromTemplate Method

Copies an existing project file, and any items or subdirectories it contains, to the specified location and adds it to the solution.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

Syntax

'Declaration
Function AddFromTemplate ( _
    FileName As String, _
    Destination As String, _
    ProjectName As String, _
    Exclusive As Boolean _
) As Project
Project AddFromTemplate(
    string FileName,
    string Destination,
    string ProjectName,
    bool Exclusive
)
Project^ AddFromTemplate(
    [InAttribute] String^ FileName, 
    [InAttribute] String^ Destination, 
    [InAttribute] String^ ProjectName, 
    [InAttribute] bool Exclusive
)
abstract AddFromTemplate : 
        FileName:string * 
        Destination:string * 
        ProjectName:string * 
        Exclusive:bool -> Project
function AddFromTemplate(
    FileName : String, 
    Destination : String, 
    ProjectName : String, 
    Exclusive : boolean
) : Project

Parameters

  • FileName
    Type: System.String

    Required. The full path and file name with extension of the template project file.

  • Destination
    Type: System.String

    Required. The full path of the directory in which to copy the contents of FileName.

  • ProjectName
    Type: System.String

    Required. The name of the project file in the destination directory. This should include the extension. The name displayed is derived from ProjectName.

  • Exclusive
    Type: System.Boolean

    Optional. Indicates whether the project loads in the current solution or its own; 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.

Return Value

Type: EnvDTE.Project
A Project object.

Remarks

The name of the project displayed in the Solution Browser is ProjectName without the file extension. AddFromTemplate fails if the new project file name already exists in the destination.

Note

For Visual Basic and Visual C# projects: The Project object returned is nulla null reference (Nothing in Visual Basic). You can find the Project object created by iterating through the DTE.Solution.Projects collection using the ProjectName parameter to identify the newly created project.

Examples

Sub SolutionExample()
   'This function creates a solution and adds a Visual Basic Console
   'project to it. 
   Dim soln As Solution
   Dim proj As Project
   Dim msg As String

   'Create a reference to the solution.
   soln = DTE.Solution

   ' Create a new solution.
   soln.Create("c:\temp2", "MyNewSolution")

   ' Create a new VB project from a template. 
   ' Adjust the template path and save path as needed.
   proj = soln.AddFromTemplate("<template path>\ConsoleApplication.vbproj", "c:\temp2", "My New Project", True)
   ' Save the new solution and project.
   soln.SaveAs("c:\temp2\newsolution.sln")
   msg = "Created new solution: " & soln.FullName & vbCrLf
   msg = msg & "Created new project: " & proj.Name
   MsgBox(msg)
End Sub

.NET Framework Security

See Also

Reference

_Solution Interface

EnvDTE Namespace