Partager via


_Solution.AddFromTemplate, méthode

Copie un fichier projet existant, ainsi que les éléments ou sous-répertoires qu'il contient, à l'emplacement spécifié, puis l'ajoute à la solution.

Espace de noms :  EnvDTE
Assembly :  EnvDTE (dans EnvDTE.dll)

Syntaxe

'Déclaration
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

Paramètres

  • FileName
    Type : System.String
    Obligatoire.Chemin d'accès complet et nom de fichier avec extension du fichier projet de modèle.
  • Destination
    Type : System.String
    Obligatoire.Chemin d'accès complet du répertoire dans lequel vous voulez copier le contenu du fichier FileName.
  • ProjectName
    Type : System.String
    Obligatoire.Nom du fichier projet tel qu'il apparaît dans le répertoire de destination.Il doit comprendre l'extension.Le nom affiché est dérivé de ProjectName.
  • Exclusive
    Type : System.Boolean
    Facultatif.Indique si le projet se charge dans la solution en cours ou dans sa propre solution ; true si la solution en cours est fermée et que le projet est ajouté à une nouvelle solution, false si le projet est ajouté à une solution ouverte existante.

Valeur de retour

Type : EnvDTE.Project
Objet Project.

Notes

Le nom du projet affiché dans l'Explorateur de solutions est ProjectName sans l'extension de fichier. AddFromTemplate échoue si le nom du fichier du nouveau projet existe déjà dans la destination.

Notes

Pour les projets Visual Basic et Visual C# : l'objet Project retourné est nullune référence null (Nothing en Visual Basic). Pour rechercher l'objet Project créé, itérez au sein de la collection DTE.Solution.Projects à l'aide du paramètre ProjectName pour identifier le nouveau projet créé.

Exemples

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

Sécurité .NET Framework

Voir aussi

Référence

_Solution Interface

EnvDTE, espace de noms