Solution3.GetProjectItemTemplates Method

Returns a collection of project item templates for the specified project.

Namespace:  EnvDTE90
Assembly:  EnvDTE90 (in EnvDTE90.dll)

Syntax

'Declaration
Function GetProjectItemTemplates ( _
    Language As String, _
    CustomDataSignature As String _
) As Templates
Templates GetProjectItemTemplates(
    string Language,
    string CustomDataSignature
)
Templates^ GetProjectItemTemplates(
    String^ Language, 
    String^ CustomDataSignature
)
abstract GetProjectItemTemplates : 
        Language:string * 
        CustomDataSignature:string -> Templates
function GetProjectItemTemplates(
    Language : String, 
    CustomDataSignature : String
) : Templates

Parameters

  • Language
    Type: System.String

    The language used to write the project item template.

  • CustomDataSignature
    Type: System.String

    The signature for any metadata associated with the project item template.

Return Value

Type: EnvDTE90.Templates
A templates collection containing the names of all of the project item templates.

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 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 9\Common7\IDE\ItemTemplates\Language.

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

Examples

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

Public Sub OnConnection(ByVal application As Object, _
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    SolutionExample(_applicationObject)
End Sub

Sub SolutionExample(ByVal dte As DTE2)
    ' This function creates a solution and adds a Visual C# Console
    ' project to it.
    Try
        Dim soln As Solution3 = CType(DTE.Solution, Solution3)
        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 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{
        Solution3 soln = (Solution3)_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);
    }
}

.NET Framework Security

See Also

Reference

Solution3 Interface

EnvDTE90 Namespace

Other Resources

How to: Compile and Run the Automation Object Model Code Examples