Metodo Solution2.AddFromFile (String, Boolean)

Aggiunge un progetto alla soluzione basata su un file di progetto è già archiviato nel sistema.

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

Sintassi

'Dichiarazione
Function AddFromFile ( _
    FileName As String, _
    Exclusive As Boolean _
) As Project
Project AddFromFile(
    string FileName,
    bool Exclusive
)
Project^ AddFromFile(
    [InAttribute] String^ FileName, 
    [InAttribute] bool Exclusive
)
abstract AddFromFile : 
        FileName:string * 
        Exclusive:bool -> Project 
function AddFromFile(
    FileName : String, 
    Exclusive : boolean
) : Project

Parametri

  • FileName
    Tipo: System.String
    obbligatorio.Il percorso completo e il nome del file di progetto.
  • Exclusive
    Tipo: System.Boolean
    facoltativo.Indica se il progetto viene caricato nella soluzione corrente o propria soluzione, true se la soluzione corrente viene chiusa e il progetto viene aggiunto a una nuova soluzione, false se il progetto viene aggiunto a un oggetto esistente, aprire la soluzione.

Valore restituito

Tipo: EnvDTE.Project
In Project oggetto.

Note

È possibile utilizzare LaunchWizard metodo anziché AddFromFile per eseguire una procedura guidata per eliminare la relativa interfaccia (UI) utente durante l'esecuzione.LaunchWizard dispone di un parametro che consente di disabilitare l'interfaccia utente.

Esempi

Per informazioni su come eseguire il codice del componente aggiuntivo, vedere Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione.

Nell'esempio seguente viene illustrato come creare una soluzione e aggiungere un progetto esistente su.

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)
    AddFromFileExample(_applicationObject)
End Sub

Sub AddFromFileExample(ByVal dte As DTE2)
    ' This add-in creates a solution and adds an 
    ' existing project to it.
    Try
        Dim soln As Solution2 =  _
        CType(_applicationObject.Solution, Solution2)
        ' Create a new solution.
        ' Make sure the path below exists on your computer.
        ' You can modify the path.
        soln.Create("c:\temp2", "MyNewSolution")
        ' Add an existing project to the new solution.
        ' Modify the path to a location that contains a
        ' Visual Studio project.
        soln.AddFromFile _
        ' Make sure to set the path below to the default project location on your computer
        ("c:\temp1\Visual Studio 2010\ _  
        Projects\ConsoleApplication\ConsoleApplication\ _
        ConsoleApplication.csproj")
    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.
    AddFromFileExample((DTE2)_applicationObject);
}
public void AddFromFileExample(DTE2 dte)
{
    // This add-in creates a soultion and adds an 
    // existing project to it. 
    try
    {
        Solution2 soln = (Solution2)_applicationObject.Solution;
        // Create a solution.
        // Make sure that the file path specified below
        // exists on your computer.
        // You can modify the path.
        soln.Create("c:\temp2", "MyNewSolution");
        // Add an existing project to the new solution.
        // Modify the path to a location that contains
        // a Visual Studio project.
        soln.AddFromFile("c:\temp1"
\Visual Studio 2010\Projects\ConsoleApplication
\ConsoleApplication\ ConsoleApplication.csproj", true);
        }
    catch(SystemException ex)
    {
        MessageBox.Show("ERROR: " + ex);
    }
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

Solution2 Interfaccia

Overload AddFromFile

Spazio dei nomi EnvDTE80