Export (0) Print
Expand All

Solution2.GetProjectItemTemplate Method 

Returns a path to the indicated project item template.

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

string GetProjectItemTemplate (
	string TemplateName,
	string Language
)
String GetProjectItemTemplate (
	String TemplateName, 
	String Language
)
function GetProjectItemTemplate (
	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 item 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 GetProjectItemTemplate can be supplied in a number of different ways as shown below:

  • Pass in the GUID for a Smart Device Visual Basic Virtual Project as the Language parameter, and the name of the zip file as the TemplateName.

    GetProjectItemTemplate("NETCFv2-Class.zip", "{3114F5B0-E435-4bc5-A03D-168E20D9BF83}");
    
  • Pass in the GUID for a Smart Device Visual Basic Virtual Project as the Language parameter, and the "Class" string as the TemplateName. The string "Class" is derived from the folder hierarchy and is referred to as the user interface (UI) string. Other UI strings are "HTML Page" and "Splash Screen". The UI strings are locale dependent. Using the name of the zip file is the safest way to pass the TemplateName parameter.

    GetProjectItemTemplate("Class", "{3114F5B0-E435-4bc5-A03D-168E20D9BF83}");
    
  • Pass in the string "VisualBasic" as the Language parameter, and the name of the zip file for the TemplateName parameter. This works because NETCFv2-Class.zip is unique to Smart Devices.

    GetProjectItemTemplate("NETCFv2-Class.zip", "VisualBasic/SmartDevice-NETCFv2");
    

You can also create custom templates for project items. 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 paths for your templates in the Visual Studio user item templates location boxes. Alternatively, you can accept the default location.

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\ItemTemplates\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.
    SolnGetProjetItemExample((DTE2)_applicationObject);
}
public void SolnGetProjetItemExample(DTE2 dte)
{
    // This add-in adds an item to a Visual Basic solution.
    // Open a Visual Basic solution in Visual Studio 
    // before running this example.
 
    Solution2 soln = (Solution2)_applicationObject.Solution;
    Project prj;
    ProjectItem prjItem;
    string itemPath;
    try
    {

        prj = soln.Projects.Item(1);
        itemPath = 
soln.GetProjectItemTemplate("HTMLPage.zip", "VisualBasic");
        // Create a new project item based on the template. 
        // (In this case, an HTML page.)
        prjItem = 
prj.ProjectItems.AddFromTemplate(itemPath, "MyNewHtml");

    }
    catch (SystemException ex)
    {
        MessageBox.Show("ERROR: " + ex);
    }
}
Show:
© 2014 Microsoft