Export (0) Print
Expand All
Cut
Run
Expand Minimize

AddFromTemplate Method (Solution Object)

Visual Studio .NET 2003

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

[Visual Basic .NET]
Public Function AddFromTemplate( _
   ByVal FileName As String, _
   ByVal Destination As String, _
   ByVal ProjectName As String, _
   Optional ByVal Exclusive As Boolean = False _
) As Project
[Visual Basic 6]
Function AddFromTemplate( _
   ByVal FileName As String, _
   ByVal Destination As String, _
   ByVal ProjectName As String, _
   Optional ByVal Exclusive As Boolean = False _
) As Project
[C++]
HRESULT __stdcall AddFromTemplate(
   BSTR FileName,
   BSTR Destination,
   BSTR ProjectName,
   VARIANT_BOOL Exclusive,
   /* [out, retval] */ Project** retVal
);
[C#]
Project AddFromTemplate(
   string FileName,
   string Destination,
   string ProjectName,
   bool Exclusive
);
[JScript .NET]
public function AddFromTemplate(
   FileName : String,
   Destination : String,
   ProjectName : String,
   Exclusive : Boolean
) : Project

Parameters

FileName
Required. The full path and file name with extension of the template project file.
Destination
Required. The full path of the directory in which to copy the contents of FileName.
ProjectName
Required. The name of the project file in the destination directory. This should include the extension. The name displayed is derived from ProjectName.
Exclusive
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

Returns 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 has a value of Nothing. 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.

Example

Sub SolutionExample()
   'This function creates a solution and adds a Visual Basic .NET 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 Console application project. Adjust the save path as 
   'needed.
   proj = soln.AddFromTemplate("D:\Program Files\Microsoft Visual Studio .NET\Vb7\VBWizards\ConsoleApplication\Templates\1033\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

See Also

AddFromFile Method (Solution Object) | LaunchWizard Method (DTE Object) | Remove Method (Solution Object)

Applies To: Solution Object

Show:
© 2014 Microsoft