Partager via


VSProject.TemplatePath, propriété

Obtient le chemin d'accès complet au répertoire contenant les modèles d'élément du projet pour Visual Basic ou C#. En lecture seule.

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

Syntaxe

'Déclaration
ReadOnly Property TemplatePath As String
    Get
string TemplatePath { get; }
property String^ TemplatePath {
    String^ get ();
}
abstract TemplatePath : string
function get TemplatePath () : String

Valeur de propriété

Type : System.String
Retourne une valeur de chaîne représentant le chemin d'accès au modèle.

Notes

Cette propriété retourne le chemin d'accès du répertoire de modèles approprié, selon qu'il s'agit d'un projet Visual Basic ou C#.

Les éléments de projet personnalisés, tels que formulaires et modules, peuvent être copiés sous le chemin d'accès aux modèles. Ils peuvent alors servir de modèles pour de nouveaux éléments. La méthode AddFromTemplate de l'objet ProjectItems crée une copie du modèle dans le répertoire de projet et ajoute l'élément de projet au projet spécifié. Voici un exemple :

Exemples

[Visual Basic]

' Macro Editor
' Uses the template path to add a copy of the 
' CompanyTemplate form to the project.
Imports VSLangProj
Sub TemplatePathExample()
   ' This example assumes that the first project in the solution is 
   ' either a Visual Basic or C# project.
   Dim aVSProject As VSProject = _
      CType(DTE.Solution.Projects.Item(1).Object, VSProject)
        
   ' Use the path to create a new project item.
   Dim aProject As Project = DTE.Solution.Projects.Item(1)
   Dim thePath As String = aVSProject.TemplatePath
   Dim formName As String = InputBox("Name of new form with extension:")
   Dim newItem As ProjectItem
   newItem = aProject.ProjectItems.AddFromTemplate(thePath & _
      "\CompanyTemplate.vb", formName)
End Sub

Sécurité .NET Framework

Voir aussi

Référence

VSProject Interface

VSLangProj, espace de noms