Solution4.GetProjectItemTemplates(String, String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回指定项目的项目项模板的集合。
public:
EnvDTE90::Templates ^ GetProjectItemTemplates(System::String ^ Language, System::String ^ CustomDataSignature);
[System.Runtime.InteropServices.DispId(205)]
public EnvDTE90.Templates GetProjectItemTemplates (string Language, string CustomDataSignature);
[<System.Runtime.InteropServices.DispId(205)>]
abstract member GetProjectItemTemplates : string * string -> EnvDTE90.Templates
Public Function GetProjectItemTemplates (Language As String, CustomDataSignature As String) As Templates
参数
- Language
- String
用于编写项目项模板的语言。
- CustomDataSignature
- String
与项目项模板关联的任何元数据的签名。
返回
一个模板集合,其中包含所有项目项模板的名称。
实现
- 属性
示例
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);
}
}
注解
项目模板存储为 zip 文件。 此方法按名称和语言请求项目,并返回模板的路径。
可以通过多种 GetProjectItemTemplate 不同的方式提供的参数,如下所示:
传入智能设备 Visual Basic 虚拟项目的 GUID 作为
Language参数,将 zip 文件的名称作为TemplateName。GetProjectItemTemplate("NETCFv2-Class.zip", "{3114F5B0-E435-4bc5-A03D-168E20D9BF83}");传入智能设备 Visual Basic 虚拟项目的 GUID 作为
Language参数,并传入作为的 "类" 字符串TemplateName。 字符串 "Class" 派生自文件夹层次结构,被称为用户界面 (UI) 字符串。 其他 UI 字符串为 "HTML 页" 和 "初始屏幕"。 UI 字符串依赖于区域设置。 使用 zip 文件的名称是传递参数的最安全方式TemplateName。GetProjectItemTemplate("Class", "{3114F5B0-E435-4bc5-A03D-168E20D9BF83}");传入字符串 ""
Language,作为参数,并传入参数的 zip 文件的名称TemplateName。 这是因为 NETCFv2-Class.zip 在智能设备中是唯一的。GetProjectItemTemplate("NETCFv2-Class.zip", "VisualBasic/SmartDevice-NETCFv2");
你还可以为项目项创建自定义模板。 若要指定将在其中存储模板的目录,请单击 "工具" 菜单上的 "选项"。 在 " 选项 " 对话框的左窗格中,单击 " 项目和解决方案"。 在 " Visual Studio 用户项模板位置 " 框中键入模板的路径。 或者,您可以接受默认位置。
自定义模板要求唯一的文件名不与中定义的文件名冲突:
<drive>: \Program Files\Microsoft Visual Studio 9 \ Common7\IDE\ItemTemplates \ Language。
请确保使用 (的长文件名,而不是 8dot3) 。 有关详细信息,请参阅 钢笔:创建项目和项模板。