Solution4.AddFromTemplate(String, String, String, Boolean) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将现有项目文件及其包含的任何项或子目录复制到指定位置,并将其添加到解决方案。
EnvDTE::Project AddFromTemplate(std::wstring const & FileName, std::wstring const & Destination, std::wstring const & ProjectName, bool Exclusive = true);
[System.Runtime.InteropServices.DispId(15)]
public EnvDTE.Project AddFromTemplate (string FileName, string Destination, string ProjectName, bool Exclusive = true);
[<System.Runtime.InteropServices.DispId(15)>]
abstract member AddFromTemplate : string * string * string * bool -> EnvDTE.Project
Public Function AddFromTemplate (FileName As String, Destination As String, ProjectName As String, Optional Exclusive As Boolean = true) As Project
参数
- FileName
- String
必需。 模板项目文件的完整路径和带有扩展名的文件名。
- Destination
- String
必需。 文件名的内容要复制到的目录的完整路径。
- ProjectName
- String
必需。 目标目录中的项目文件的名称。 它应包含扩展名。 显示的名称是从 项目名称派生的。
- Exclusive
- Boolean
可选。 指示项目是加载到当前解决方案中还是加载到它自己的解决方案中;如果当前解决方案已关闭,并且项目添加到新的解决方案中,则为 true;如果项目添加到已打开的现有解决方案中,则为 false。
返回
Project 对象。
实现
- 属性
示例
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
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);
}
}
注解
解决方案资源管理器 中显示的项目的名称没有 ProjectName 文件扩展名。 AddFromTemplate 如果目标中已存在新项目文件名,则会失败。
备注
对于 Visual Basic 和 Visual C# 项目:返回的 Project 对象的值为 Nothing 或 null 。 你可以通过 Project DTE.Solution.Projects 使用 ProjectName 参数来确定新创建的项目,来找到创建的对象,方法是循环访问集合。