_Solution.AddFromTemplate 方法

将现有项目文件及其包含的任何项或子目录复制到指定位置,并将其添加到解决方案。

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

语法

声明
Function AddFromTemplate ( _
    FileName As String, _
    Destination As String, _
    ProjectName As String, _
    Exclusive As Boolean _
) As Project
Project AddFromTemplate(
    string FileName,
    string Destination,
    string ProjectName,
    bool Exclusive
)
Project^ AddFromTemplate(
    [InAttribute] String^ FileName, 
    [InAttribute] String^ Destination, 
    [InAttribute] String^ ProjectName, 
    [InAttribute] bool Exclusive
)
abstract AddFromTemplate : 
        FileName:string * 
        Destination:string * 
        ProjectName:string * 
        Exclusive:bool -> Project 
function AddFromTemplate(
    FileName : String, 
    Destination : String, 
    ProjectName : String, 
    Exclusive : boolean
) : Project

参数

  • FileName
    类型:System.String
    必选。模板项目文件的完整路径和带有扩展名的文件名。
  • Destination
    类型:System.String
    必选。 FileName 的内容所要复制到的目录的完整路径。
  • ProjectName
    类型:System.String
    必选。目标目录中的项目文件的名称。它应包含扩展名。显示的名称派生自 ProjectName。
  • Exclusive
    类型:System.Boolean
    可选。指示项目是加载到当前解决方案中还是加载到自己的解决方案中;如果当前解决方案已关闭,项目被添加到新的解决方案,则为 true;如果项目被添加到现有的打开的解决方案,则为 false。

返回值

类型:EnvDTE.Project
一个 Project 对象。

备注

在解决方案浏览器中显示的项目名称是没有文件扩展名的 ProjectName。若新项目文件名在目标中已存在,则 AddFromTemplate 失败。

说明说明

对于 Visual Basic 和 Visual C# 项目:返回的 Project 对象为 nullnull 引用(在 Visual Basic 中为 Nothing)。可以查找所创建的 Project 对象,方法是使用 ProjectName 参数循环访问 DTE.Solution.Projects 集合,以标识新创建的项目。

示例

Sub SolutionExample()
   'This function creates a solution and adds a Visual Basic Console
   'project to it. 
   Dim soln As Solution
   Dim proj As Project
   Dim msg As String

   'Create a reference to the solution.
   soln = DTE.Solution

   ' Create a new solution.
   soln.Create("c:\temp2", "MyNewSolution")

   ' Create a new VB project from a template. 
   ' Adjust the template path and save path as needed.
   proj = soln.AddFromTemplate("<template path>\ConsoleApplication.vbproj", "c:\temp2", "My New Project", True)
   ' Save the new solution and project.
   soln.SaveAs("c:\temp2\newsolution.sln")
   msg = "Created new solution: " & soln.FullName & vbCrLf
   msg = msg & "Created new project: " & proj.Name
   MsgBox(msg)
End Sub

.NET Framework 安全性

请参见

参考

_Solution 接口

EnvDTE 命名空间