Export (0) Print
Expand All

Solution2.GetProjectTemplate Method 

Returns a path to the indicated project template.

Namespace: EnvDTE80
Assembly: EnvDTE80 (in envdte80.dll)

string GetProjectTemplate (
	string TemplateName,
	string Language
)
String GetProjectTemplate (
	String TemplateName, 
	String Language
)
function GetProjectTemplate (
	TemplateName : String, 
	Language : String
) : String

Parameters

TemplateName

The name of the template.

Language

The language used to write the template.

Return Value

The full name of the project template.

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".

    NoteNote

    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 Creating Project and Item Templates.

For information on how to run this add-in code, see How to: Compile and Run the Automation Object Model Code Examples.

using System.Windows.Forms;
public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst,
 ref System.Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    SolutionExample((DTE2)_applicationObject);
}

public void SolutionExample(DTE2 dte)
{
    // This function creates a solution and adds a Visual C# Console
    // project to it.
    try{
        Solution2 soln = (Solution2)_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);
    }
}
Show:
© 2014 Microsoft