返回指定项目模板的路径。
命名空间: EnvDTE90
程序集: EnvDTE90(在 EnvDTE90.dll 中)
语法
声明
Function GetProjectTemplate ( _
TemplateName As String, _
Language As String _
) As String
string GetProjectTemplate(
string TemplateName,
string Language
)
String^ GetProjectTemplate(
String^ TemplateName,
String^ Language
)
abstract GetProjectTemplate :
TemplateName:string *
Language:string -> string
function GetProjectTemplate(
TemplateName : String,
Language : String
) : String
参数
- TemplateName
类型:System.String
模板的名称。
- Language
类型:System.String
用于编写模板的语言。
返回值
类型:System.String
项目模板的全名。
实现
Solution2.GetProjectTemplate(String, String)
备注
项目模板存储为 zip 文件。 此方法按名称和语言查找项目,并返回模板的路径。
可以按许多不同的方法提供 GetProjectTemplate 的参数,如下所示:
以 Language 参数形式传入“CSharp”,以 TemplateName 形式传入 zip 文件的名称。
GetProjectTemplate("PocketPC2003-ClassLibrary.zip", "CSharp");以 Language 参数形式传入“CSharp”,传入一个部分文件路径“PocketPC2003\ClassLibrary.vstemplate”以便唯一地指定 TemplateName。
GetProjectTemplate("PocketPC2003\ClassLibrary.vstemplate", "CSharp");//partial file path以 Language 参数形式传入字符串“CSharp”,以 TemplateName 参数形式传入字符串“Pocket PC 2003 类库”。 字符串“Pocket PC 2003 类库”从文件夹层次结构派生,它被称作用户界面 (UI) 字符串。 UI 字符串的其他示例有“控制台应用程序”和“Windows 应用程序”。
提示
UI 字符串因区域设置的不同而异。 使用 zip 文件的名称是最安全的传递 TemplateName 参数的方法。
GetProjectTemplate("Pocket PC 2003 Class Library", "CSharp");以 Language 参数形式传入字符串“CSharp”,以 TemplateName 参数形式传入字符串“PocketPC2003\Pocket PC 2003 类库”。 这将包括一个用来唯一地指定模板的 UI 字符串和部分路径。
GetProjectTemplate("PocketPC2003\Pocket PC 2003 Class Library", "CSharp");
您还可以创建自己的自定义项目模板。 若要指定将在其中存储您的模板的目录,请单击**“工具”菜单中的“选项”。 在“选项”对话框的左侧窗格中,单击“项目和解决方案”。 在“Visual Studio 用户项目模板位置”**框中键入模板的路径。 或者,您可以接受默认位置。
自定义模板需要唯一的文件名,且不与下面路径中定义的文件名冲突:
- <驱动器>:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\语言
请确保使用长文件名(而非 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 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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。