Partager via


Solution3.AddFromFile, méthode

Ajoute un projet à la solution qui est basée sur un fichier projet déjà stocké dans le système.

Espace de noms :  EnvDTE90
Assembly :  EnvDTE90 (dans EnvDTE90.dll)

Syntaxe

'Déclaration
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

Paramètres

  • FileName
    Type : String

    Requis. Chemin d'accès complet et nom de fichier du fichier projet.

  • Exclusive
    Type : Boolean

    Optionnel. Indique si le projet se charge dans la solution en cours ou dans sa propre solution ; true si la solution en cours est fermée et que le projet est ajouté à une nouvelle solution, false si le projet est ajouté à une solution ouverte existante.

Valeur de retour

Type : Project
Objet Project.

Notes

Vous pouvez utiliser la méthode LaunchWizard plutôt que AddFromFile pour exécuter un Assistant si vous souhaitez supprimer son interface utilisateur pendant l'exécution. LaunchWizard a un paramètre qui vous permet de désactiver l'interface utilisateur.

Exemples

Pour plus d'informations sur l'exécution de ce code de complément, consultez Comment : compiler et exécuter les exemples de code du modèle objet Automation.

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 Solution3 =  _
        CType(_applicationObject.Solution, Solution3)
        ' 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 _
        ("<default project location>\Visual Studio 2005\ _
        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
    {
        Solution3 soln = (Solution3)_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(@"<default project location>
          \Visual Studio 2005\Projects\ConsoleApplication
          \ConsoleApplication\ ConsoleApplication.csproj", true);
        }
    catch(SystemException ex)
    {
        MessageBox.Show("ERROR: " + ex);
    }
}

Sécurité .NET Framework

Voir aussi

Référence

Solution3 Interface

EnvDTE90, espace de noms

Autres ressources

Comment : compiler et exécuter les exemples de code du modèle objet Automation