Udostępnij za pośrednictwem


Solution4.GetProjectTemplate(String, String) Method

Definition

Returns a path to the specified project template.

If a template has a RequiredFrameworkVersion element higher than 4.0, you should provide the version in the call so that the search for the template will find a match. For example, instead of calling GetProjectTemplate("Extensibility\1033\VSIXProject.zip", "CSharp"); call 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

Parameters

TemplateName
String

The name of the template.

Language
String

The language used to write the template.

Returns

The full name of the project template.

Implements

Attributes

Examples

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);  
    }  
}  

Remarks

Project templates are stored as zip files. This method asks for the project by name and language and returns the path to the template.

The parameters of GetProjectTemplate can be supplied in a number of different ways as shown below:

  • Pass in "CSharp" as the Language parameter, and the name of the zip file as the TemplateName.

    GetProjectTemplate("PocketPC2003-ClassLibrary.zip", "CSharp");  
    
  • Pass in "CSharp" as the Language parameter, and a partial file path;" PocketPC2003\ClassLibrary.vstemplate", to uniquely specify the TemplateName.

    GetProjectTemplate("PocketPC2003\ClassLibrary.vstemplate", "CSharp");//partial file path  
    
  • Pass in the string "CSharp" as the Language parameter, and the string "Pocket PC 2003 Class Library" for the TemplateName parameter. The string "Pocket PC 2003 Class Library" is derived from the folder hierarchy and is referred to as the user interface (UI) string. Other examples of UI strings are "Console Application" and "Windows Application".

    Note

    The UI strings vary according to locale. Using the name of the zip file is the safest way to pass the TemplateName parameter.

    GetProjectTemplate("Pocket PC 2003 Class Library", "CSharp");  
    
  • Pass in the string "CSharp" as the Language parameter and the string "PocketPC2003\Pocket PC 2003 Class Library" for the TemplateName parameter. This includes the UI string and a partial path to uniquely specify the template.

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

You can also create your own custom project templates. To specify the directory in which you will store your templates, click Options on the Tools menu. On the left pane of the Options dialog box, click Projects and Solutions. Type the path for your templates in the Visual Studio user project templates location box. Alternatively, you can accept the default locations.

Custom templates require unique file names that do not conflict with the file names defined in:

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

Ensure that you use long file names (as opposed to 8dot3). For more information, see NIB: Creating Project and Item Templates.

Applies to