Solution4.GetProjectItemTemplates 方法 (String, String)

返回指定项目的项目项模板的集合。

命名空间:  EnvDTE100
程序集:  EnvDTE100(在 EnvDTE100.dll 中)

语法

声明
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

参数

  • Language
    类型:System.String
    用于编写项目项模板的语言。
  • CustomDataSignature
    类型:System.String
    与项目项模板关联的任何元数据的签名。

返回值

类型:EnvDTE90.Templates
一个模板集合,其中包含所有项目项模板的名称。

实现

Solution3.GetProjectItemTemplates(String, String)

备注

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

可以按许多不同的方法提供 GetProjectItemTemplate 的参数,如下所示:

  • 以 Language 参数形式传入智能设备 Visual Basic 虚拟项目的 GUID,以 TemplateName 形式传入 zip 文件的名称。

    GetProjectItemTemplate("NETCFv2-Class.zip", "{3114F5B0-E435-4bc5-A03D-168E20D9BF83}");
    
  • 以 Language 参数形式传入智能设备 Visual Basic 虚拟项目的 GUID,以 TemplateName 形式传入字符串“Class”。 字符串“Class”从文件夹层次结构派生,它被称作用户界面 (UI) 字符串。 其他 UI 字符串有“HTML 页”和“初始屏幕”。 UI 字符串与区域设置有关。 使用 zip 文件的名称是最安全的传递 TemplateName 参数的方法。

    GetProjectItemTemplate("Class", "{3114F5B0-E435-4bc5-A03D-168E20D9BF83}");
    
  • 以 Language 参数形式传入字符串“VisualBasic”,以 TemplateName 参数形式传入 zip 文件的名称。 这之所以有效,是因为 NETCFv2-Class.zip 对于智能设备是唯一的。

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

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

自定义模板需要唯一的文件名,且不与下面路径中定义的文件名冲突:

<驱动器>:\Program Files\Microsoft Visual Studio 9\Common7\IDE\ItemTemplates\语言。

请确保使用长文件名(而非 8.3 文件名)。 有关更多信息,请参见 创建项目模板和项模板

示例

有关如何运行此外接程序代码的信息,请参见如何:编译和运行自动化对象模型代码示例

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

.NET Framework 安全性

请参见

参考

Solution4 接口

GetProjectItemTemplates 重载

EnvDTE100 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例