SolutionFolder.AddFromTemplate(String, String, String) Метод

Определение

Добавляет в папку решений новый проект на основе шаблона проекта.

public:
 EnvDTE::Project ^ AddFromTemplate(System::String ^ FileName, System::String ^ Destination, System::String ^ ProjectName);
public:
 EnvDTE::Project ^ AddFromTemplate(Platform::String ^ FileName, Platform::String ^ Destination, Platform::String ^ ProjectName);
EnvDTE::Project AddFromTemplate(std::wstring const & FileName, std::wstring const & Destination, std::wstring const & ProjectName);
[System.Runtime.InteropServices.DispId(5)]
public EnvDTE.Project AddFromTemplate (string FileName, string Destination, string ProjectName);
[<System.Runtime.InteropServices.DispId(5)>]
abstract member AddFromTemplate : string * string * string -> EnvDTE.Project
Public Function AddFromTemplate (FileName As String, Destination As String, ProjectName As String) As Project

Параметры

FileName
String

Полный путь к шаблону проекта.

Destination
String

Это полный путь к каталогу, в который копируется содержимое файла .

ProjectName
String

Имя создаваемого нового проекта.

Возвращаемое значение

Project

Объект Project.

Атрибуты

Примеры

В этом примере создается новая папка решения и в нее добавляется проект из существующего файла. Он также добавляет проект из шаблона. Перед запуском этого примера создайте папку «Projects» (проекты) на главном диске (в этом примере — «C:») и создайте Visual C# проект библиотеки классов с именем «ClassLibrary1» в этой папке. Кроме того, необходимо создать папку с именем "Микспрожект" в папке "Projects". Visual StudioПеред выполнением этого примера откройте проект в интегрированной среде разработки (IDE).

Imports EnvDTE  
Imports EnvDTE80  
Sub solnFolderAddFromTemplateExample(ByVal dte As DTE2)  
    ' Before running this example, create a "Projects" folder  
    ' off your main drive ("C:" in this example), and create a C#   
    ' class library project, named ClassLibrary1 in that folder.  
    Dim soln As Solution2 = CType(_applicationObject.Solution _  
    , Solution2)  
    Dim prj As Project  
    Dim sb As New System.Text.StringBuilder  
    Dim SF As SolutionFolder  
    Try  
        Dim prjPath As String = _  
         "C:\Projects\ClassLibrary1\ClassLibrary1\ClassLibrary1.csproj"  
        ' Open a project in the Visual Studio IDE before   
        ' running this example.  
        ' Add a solution folder.  
        prj = soln.AddSolutionFolder("A new soln folder")  
        SF = CType(prj.Object, SolutionFolder)  
        ' Add a project to the new solution folder.  
        SF.AddFromFile(prjPath)  
        MsgBox("Added a new solution folder that contains a  _  
        C# project named ClassLibrary1.")  
        ' Get the project template path for a C# console project.  
        Dim csTemplatePath As String = soln.GetProjectTemplate _  
         ("Console Application", "CSharp")  
        ' Before running this example, create a   
        ' "Projects\MyCSProject" folder  
        ' off your main drive ("C:" in this example).  
        Dim prjPath2 As String = "C:\Projects\MyCSProject"  
        ' Add a new C# Console project to the solution folder   
        ' by using the template obtained above.  
        SF.AddFromTemplate(csTemplatePath, prjPath2, _  
         "New CSharp Console Project")  
        MsgBox("Added a new project from template  _  
        to the solution folder.")  
    Catch ex As System.Exception  
        MsgBox(ex.ToString)  
    End Try  
End Sub  
using EnvDTE;  
using EnvDTE80;  
using System.Windows.Forms;  
public void solnFolderAddFromTemplateExample(DTE2 dte)  
{  
    // Before running this example, create a "Projects" folder  
    // off your main drive (C: in this example), and create a C#   
    // class library project, named ClassLibrary1 in that folder.  
    Solution2 soln = (Solution2)_applicationObject.Solution;  
    Project prj;  
    System.Text.StringBuilder sb = new System.Text.StringBuilder();  
    SolutionFolder SF;  
    try  
    {  
        String prjPath = "C:\\Projects\\ClassLibrary1  
\\ClassLibrary1\\ClassLibrary1.csproj";  
        // Open a project in the Visual Studio IDE before   
        // running this example.  
        // Add a solution folder.  
        prj = soln.AddSolutionFolder("A new soln folder");  
        SF = (SolutionFolder)prj.Object;  
        // Add a project to the new solution folder.  
        SF.AddFromFile(prjPath);  
        MessageBox.Show("Added a new solution folder that contains a   
C# project named ClassLibrary1.");  
        // Get the project template path for a C# console project.  
        String csTemplatePath = soln.GetProjectTemplate  
("Console Application", "CSharp");  
        // Before running this example, create   
        // a "Projects\MyCSProject" folder  
        // off your main drive ("C:" in this example).  
        String prjPath2 = "C:\\Projects\\MyCSProject";  
        // Add a new C# Console project to the solution folder  
        // by using the template obtained above.  
        SF.AddFromTemplate(csTemplatePath, prjPath2,  
 "New CSharp Console Project");  
        MessageBox.Show("Added a new project from   
template to the solution folder.");  
    }  
    catch(SystemException ex)  
    {  
        MessageBox.Show(ex.ToString());  
    }  
}  

Комментарии

Этот вызов завершается неудачей, если новое имя файла проекта уже существует в назначении.

Применяется к