Solution4.GetProjectTemplate(String, String) 方法

定义

返回指定项目模板的路径。

如果模板具有一个大于 4.0 版的 RequiredFrameworkVersion 元素,则应该在调用中提供该版本,以使模板的搜索找到匹配。 例如,不是调用 GetProjectTemplate ( "Extensibility\1033\VSIXProject.zip"、"CSharp" ) ;调用 GetProjectTemplate ( "Extensibility\1033\VSIXProject.zip|FrameworkVersion = 4.5 "," CSharp ") ;

public:
 System::String ^ GetProjectTemplate(System::String ^ TemplateName, System::String ^ Language);
public:
 Platform::String ^ GetProjectTemplate(Platform::String ^ TemplateName, Platform::String ^ Language);
std::wstring GetProjectTemplate(std::wstring const & TemplateName, std::wstring const & Language);
[System.Runtime.InteropServices.DispId(103)]
public string GetProjectTemplate (string TemplateName, string Language);
[<System.Runtime.InteropServices.DispId(103)>]
abstract member GetProjectTemplate : string * string -> string
Public Function GetProjectTemplate (TemplateName As String, Language As String) As String

参数

TemplateName
String

模板的名称。

Language
String

用于编写模板的语言。

返回

String

项目模板的全名。

实现

属性

示例

Sub SolutionExample(ByVal dte As DTE2)  
    ' This function creates a solution and adds a Visual C# Console  
    ' project to it.  
    Try  
        Dim soln As Solution4 = CType(DTE.Solution, Solution4)  
        Dim csTemplatePath As String  
        ' This path must exist on your computer.  
        ' Replace <file path> below with an actual path.  
        Dim csPrjPath As String = "<file path>"  
        MsgBox("starting")  
        ' Get the project template path for a C# console project.  
        csTemplatePath = soln.GetProjectTemplate _  
        ("ConsoleApplication.zip", "CSharp")  
        ' Create a new C# Console project using the template obtained   
        ' above.  
        soln.AddFromTemplate(csTemplatePath, csPrjPath, _  
        "New CSharp Console Project", False)  
        MsgBox("done")  
    Catch ex As System.Exception  
        MsgBox(ex.ToString)  
    End Try  
End Sub  
using System.Windows.Forms;  
public void SolutionExample(DTE2 dte)  
{  
    // This function creates a solution and adds a Visual C# Console  
    // project to it.  
    try{  
        Solution4 soln = (Solution4)_applicationObject.Solution;  
        String csTemplatePath;  
        // The file path must exist on your computer.  
        // Replace <file path> below with an actual path.  
        String csPrjPath = "<file path>";  
        "<file path>MessageBox.Show("Starting...");  
        "<file path>"<file path>csTemplatePath =   
          soln.GetProjectTemplate("ConsoleApplication.zip", "CSharp");  
        // Create a new C# Console project using the template obtained   
        // above.  
        soln.AddFromTemplate(csTemplatePath, csPrjPath,  
          "New CSharp Console Project", false);  
        MessageBox.Show("Done!");  
    }  
    catch(SystemException ex)  
    {  
        MessageBox.Show("ERROR: " + ex);  
    }  
}  

注解

项目模板存储为 zip 文件。 此方法按名称和语言请求项目,并返回模板的路径。

可以通过多种 GetProjectTemplate 不同的方式提供的参数,如下所示:

  • 传入 "CSharp" 作为 Language 参数,将 zip 文件的名称作为 TemplateName

    GetProjectTemplate("PocketPC2003-ClassLibrary.zip", "CSharp");  
    
  • 传入 "CSharp" 作为 Language 参数,并传入部分文件路径; "PocketPC2003\ClassLibrary.vstemplate ",用于唯一指定 TemplateName

    GetProjectTemplate("PocketPC2003\ClassLibrary.vstemplate", "CSharp");//partial file path  
    
  • 传入字符串 "CSharp" 作为 Language 参数,并传入参数的字符串 "POCKET PC 2003 类库" TemplateName 。 字符串 "Pocket PC 2003 类库" 派生自文件夹层次结构,被称为用户界面 (UI) 字符串。 用户界面字符串的其他示例包括 "控制台应用程序" 和 "Windows 应用程序"。

    备注

    UI 字符串因区域设置而异。 使用 zip 文件的名称是传递参数的最安全方式 TemplateName

    GetProjectTemplate("Pocket PC 2003 Class Library", "CSharp");  
    
  • 传入字符串 "CSharp" 作为 Language 参数,并传入参数的字符串 "POCKETPC2003\POCKET PC 2003 类库" TemplateName 。 这包括 UI 字符串和用于唯一指定模板的部分路径。

    GetProjectTemplate("PocketPC2003\Pocket PC 2003 Class Library", "CSharp");  
    

您还可以创建自己的自定义项目模板。 若要指定将在其中存储模板的目录,请单击 "工具" 菜单上的 "选项"。 在 " 选项 " 对话框的左窗格中,单击 " 项目和解决方案"。 在 " Visual Studio 用户项目模板位置 " 框中键入模板的路径。 或者,您可以接受默认位置。

自定义模板要求唯一的文件名不与中定义的文件名冲突:

  • <drive>: \Program Files\Microsoft Visual Studio 8 \ Common7\IDE\ProjectTemplates \ Language

请确保使用 (的长文件名,而不是 8dot3) 。 有关详细信息,请参阅 钢笔:创建项目和项模板

适用于