Metodo Solution4.AddFromTemplate (String, String, String, Boolean)

Copia nella posizione specificata un file di progetto esistente e tutti gli elementi o le sottodirectory in esso contenuti e aggiunge il file alla soluzione.

Spazio dei nomi:  EnvDTE100
Assembly:  EnvDTE100 (in EnvDTE100.dll)

Sintassi

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

Parametri

  • FileName
    Tipo: System.String
    Obbligatorio.Il percorso completo e il nome del file con l'estensione del file di progetto utilizzato come modello.
  • Destination
    Tipo: System.String
    Obbligatorio.Percorso completo della directory in cui copiare il contenuto di FileName.
  • ProjectName
    Tipo: System.String
    Obbligatorio.Il nome del file di progetto nella directory di destinazione.Tale nome deve includere l'estensione.Il nome visualizzato è derivato da ProjectName.
  • Exclusive
    Tipo: System.Boolean
    Parametro facoltativo.Indica se il progetto viene caricato nella soluzione corrente o in una soluzione separata. true se la soluzione corrente è chiusa e il progetto viene aggiunto a una nuova soluzione, false se il progetto viene aggiunto alla soluzione aperta esistente.

Valore restituito

Tipo: EnvDTE.Project
Oggetto Project.

Note

Il nome del progetto visualizzato in Esplora soluzioni è ProjectName senza estensione del file.AddFromTemplate ha esito negativo se il nome file del nuovo progetto è già presente nella destinazione.

[!NOTA]

Nei progetti di Visual Basic e Visual C#: l'oggetto Project restituito dispone di un valore Nothing o nullriferimento null (Nothing in Visual Basic).Per individuare l'oggetto Project creato è possibile scorrere la raccolta DTE.Solution.Projects utilizzando il parametro ProjectName per identificare il nuovo progetto creato.

Esempi

Per informazioni sulla modalità di esecuzione di questo codice di componente aggiuntivo, vedere Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione.

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 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 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{
        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);
    }
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

Solution4 Interfaccia

Overload AddFromTemplate

Spazio dei nomi EnvDTE100

Altre risorse

Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione