Udostępnij za pośrednictwem


Metoda SolutionFolder.AddFromTemplate —

Dodaje nowy projekt folder rozwiązania oparte na szablonie projektu.

Przestrzeń nazw:  EnvDTE80
Zestaw:  EnvDTE80 (w EnvDTE80.dll)

Składnia

'Deklaracja
Function AddFromTemplate ( _
    FileName As String, _
    Destination As String, _
    ProjectName As String _
) As Project
Project AddFromTemplate(
    string FileName,
    string Destination,
    string ProjectName
)
Project^ AddFromTemplate(
    [InAttribute] String^ FileName, 
    [InAttribute] String^ Destination, 
    [InAttribute] String^ ProjectName
)
abstract AddFromTemplate : 
        FileName:string * 
        Destination:string * 
        ProjectName:string -> Project
function AddFromTemplate(
    FileName : String, 
    Destination : String, 
    ProjectName : String
) : Project

Parametry

  • FileName
    Typ: String

    Pełna ścieżka szablonu projektu.

  • Destination
    Typ: String

    Jest to pełna ścieżka do katalogu, w której mają być kopiowane FileName zawartość.

  • ProjectName
    Typ: String

    Nazwa nowego projektu ma zostać utworzony.

Wartość zwracana

Typ: Project
A Project object.

Uwagi

To wywołanie kończy się niepowodzeniem, jeśli nową nazwę pliku projektu już istnieje w lokalizacji docelowej.

Przykłady

W tym przykładzie tworzy nowy folder rozwiązania i dodaje do niej projektu, z istniejącego pliku.Dodaje również projektu z szablonu.Przed uruchomieniem w tym przykładzie należy utworzyć folder "Projekty" wyłączanie dysku głównego ("C:" w tym przykładzie), a następnie utwórz Visual C# library project klasy o nazwie "ClassLibrary1" w tym folderze.Należy również utworzyć folder o nazwie "MyCSProject" w folderze "Projekty".Otwórz projekt w Visual Studio zintegrowane środowisko dewelopowania (IDE) przed uruchomieniem tego dodatku.

Aby uzyskać więcej informacji o sposobach uruchamiania w tym przykładzie jako dodatek, zobacz Porady: kompilowanie i uruchamianie kodu modelu obiektów automatyzacji — przykłady.

Imports EnvDTE
Imports EnvDTE80
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)
    solnFolderAddFromTemplateExample(_applicationObject)
End Sub
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 add-in.
        ' 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 OnConnection(object application, 
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    solnFolderAddFromTemplateExample(_applicationObject);
}
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 add-in.
        // 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());
    }
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

SolutionFolder Interfejs

Przestrzeń nazw EnvDTE80