VSProject.TemplatePath 属性

定义

获取目录的完整路径,该目录包含 Visual Basic 或 c # 的项目项模板。 只读。

public:
 property System::String ^ TemplatePath { System::String ^ get(); };
public:
 property Platform::String ^ TemplatePath { Platform::String ^ get(); };
[System.Runtime.InteropServices.DispId(8)]
public string TemplatePath { [System.Runtime.InteropServices.DispId(8)] get; }
[<System.Runtime.InteropServices.DispId(8)>]
[<get: System.Runtime.InteropServices.DispId(8)>]
member this.TemplatePath : string
Public ReadOnly Property TemplatePath As String

属性值

String

返回表示模板路径的字符串值。

属性

示例

[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  

注解

此属性根据项目是 Visual Basic 项目还是 c # 项目,返回相应的模板目录路径。

可以将自定义项目项(如窗体和模块)复制到模板路径。 然后,这些项可以充当新项的模板。 AddFromTemplate对象的方法 ProjectItems 在项目目录中创建模板的副本,并将项目项添加到指定的项目中。 示例如下。

适用于