Freigeben über


Solution2.AddFromTemplate-Methode

Kopiert eine vorhandene Projektdatei sowie alle darin enthaltenen Elemente oder Unterverzeichnisse in den angegebenen Pfad und fügt sie zur Projektmappe hinzu.

Namespace:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Syntax

'Declaration
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

Parameter

  • FileName
    Typ: String

    Erforderlich. Der vollständige Pfad und Dateiname mit der Erweiterung der Vorlagenprojektdatei.

  • Destination
    Typ: String

    Erforderlich. Der vollständige Pfad des Verzeichnisses, in das der Inhalt von FileName kopiert werden soll.

  • ProjectName
    Typ: String

    Erforderlich. Der Name der Projektdatei im Zielverzeichnis. Dieser Name muss die Erweiterung enthalten. Der angezeigte Name wird von ProjectName abgeleitet.

  • Exclusive
    Typ: Boolean

    Optional. Zeigt an, ob das Projekt die aktuelle oder die eigene Projektmappe lädt: true, wenn die aktuelle Projektmappe geschlossen und das Projekt einer neuen Projektmappe hinzugefügt wird. false, wenn das Projekt der vorhandenen, geöffneten Projektmappe hinzugefügt wird.

Rückgabewert

Typ: Project
Ein Project-Objekt.

Hinweise

Der Name des im Projektmappen-Explorer angezeigten Projekts ist ProjectName ohne Dateierweiterung. AddFromTemplate schlägt fehl, wenn der Name der neuen Projektdatei am Zielort bereits vorhanden ist.

Hinweis

Für Visual Basic- und Visual C#-Projekte: Das zurückgegebene Project-Objekt hat den Wert Nothing oder nullein Nullverweis (Nothing in Visual Basic).Sie können das erstellte Project-Objekt finden, indem Sie die DTE.Solution.Projects-Auflistung unter Verwendung des ProjectName-Parameters durchlaufen, um das neu erstellte Projekt zu identifizieren.

Beispiele

Informationen zum Ausführen des Add-In-Codes finden Sie unter Gewusst wie: Kompilieren und Ausführen der Codebeispiele für das Automatisierungsobjektmodell.

Das folgende Beispiel erstellt eine Projektmappe und fügt ein Konsolenanwendungsprojekt hinzu.

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 Basic Console
    ' project to it.
    Try
        Dim soln As Solution2 = CType(DTE.Solution, Solution2)
        Dim vbTemplatePath As String
        ' This path must exist on your computer.
        ' Replace <file path> below with an actual path.
        Dim vbPrjPath As String = "<file path>"
        MsgBox("starting")
        ' Get the project template path for a Visual Basic console project.
        vbTemplatePath = soln.GetProjectTemplate _
        ("ConsoleApplication.zip", "VisualBasic")
        ' Create a new C# Console project using 
        ' the template obtained above.
        soln.AddFromTemplate(vbTemplatePath, vbPrjPath, _
        "New Visual Basic Console Project", False)
        MsgBox("done")
    Catch ex As System.Exception
        MsgBox(ex.ToString)
    End Try
End Sub
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{
        Solution2 soln = (Solution2)_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-Sicherheit

Siehe auch

Referenz

Solution2 Schnittstelle

EnvDTE80-Namespace