Share via


AssemblyInstaller.Install(IDictionary) Méthode

Définition

Effectue l'installation.

public:
 override void Install(System::Collections::IDictionary ^ savedState);
public override void Install (System.Collections.IDictionary savedState);
override this.Install : System.Collections.IDictionary -> unit
Public Overrides Sub Install (savedState As IDictionary)

Paramètres

savedState
IDictionary

IDictionary utilisé pour enregistrer les informations nécessaires à l'exécution d'une opération de validation, de restauration ou de désinstallation.

Exceptions

Le paramètre savedState a la valeur null.

- ou -

Il se peut qu'un fichier soit introuvable.

Une exception s'est produite dans le gestionnaire d'événements BeforeInstall d'un des programmes d'installation de la collection.

- ou -

Une exception s'est produite dans le gestionnaire d'événements AfterInstall d'un des programmes d'installation de la collection.

- ou -

Des types de programmes d'installation n'ont pas été détectés dans un des assemblys.

- ou -

Une instance d'un des types de programmes d'installation n'a pas pu être créée.

Exemples

L’exemple suivant illustre le AssemblyInstaller constructeur et les Install méthodes et Commit de la AssemblyInstaller classe .

Un objet de la AssemblyInstaller classe est créé en appelant le AssemblyInstaller constructeur. Les propriétés de cet objet sont définies et les Install méthodes et Commit sont appelées pour installer l’assembly « MyAssembly_Install.exe ».

#using <System.dll>
#using <System.Configuration.Install.dll>

using namespace System;
using namespace System::Configuration::Install;
using namespace System::Collections;
using namespace System::Collections::Specialized;
void main()
{
   IDictionary^ mySavedState = gcnew Hashtable;
   Console::WriteLine( "" );
   try
   {
      // Set the commandline argument array for 'logfile'.
      array<String^>^myString = {"/logFile=example.log"};
      
      // Create an Object* of the 'AssemblyInstaller' class.
      AssemblyInstaller^ myAssemblyInstaller = gcnew AssemblyInstaller;

      // Set the properties to install the required assembly.
      myAssemblyInstaller->Path = "MyAssembly_Install.exe";
      myAssemblyInstaller->CommandLine = myString;
      myAssemblyInstaller->UseNewContext = true;
      
      // Clear the 'IDictionary' Object*.
      mySavedState->Clear();
      
      // Install the 'MyAssembly_Install' assembly.
      myAssemblyInstaller->Install( mySavedState );
      
      // Commit the 'MyAssembly_Install' assembly.
      myAssemblyInstaller->Commit( mySavedState );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e );
   }
}
using System;
using System.Configuration.Install;
using System.Collections;
using System.Collections.Specialized;

class MyInstallClass
{
   static void Main()
   {
      IDictionary mySavedState = new Hashtable();

      Console.WriteLine( "" );

      try
      {
         // Set the commandline argument array for 'logfile'.
         string[] myString = new string[ 1 ];
         myString[ 0 ] = "/logFile=example.log";

         // Create an object of the 'AssemblyInstaller' class.
         AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();

         // Set the properties to install the required assembly.
         myAssemblyInstaller.Path = "MyAssembly_Install.exe";
         myAssemblyInstaller.CommandLine = myString;
         myAssemblyInstaller.UseNewContext = true;

         // Clear the 'IDictionary' object.
         mySavedState.Clear();

         // Install the 'MyAssembly_Install' assembly.
         myAssemblyInstaller.Install( mySavedState );

         // Commit the 'MyAssembly_Install' assembly.
         myAssemblyInstaller.Commit( mySavedState );
      }
      catch( Exception )
      {
      }
   }
}
Imports System.Configuration.Install
Imports System.Collections
Imports System.Collections.Specialized

Class MyInstallClass
   
   Shared Sub Main()
      Dim mySavedState = New Hashtable()
      
      Console.WriteLine("")
      

      Try
         ' Set the commandline argument array for 'logfile'.
         Dim myString(0) As String
         myString(0) = "/logFile=example.log"
         ' Create an object of the 'AssemblyInstaller' class.
         Dim myAssemblyInstaller As New AssemblyInstaller()
         ' Set the properties to install the required assembly.
         myAssemblyInstaller.Path = "MyAssembly_Install.exe"
         myAssemblyInstaller.CommandLine = myString
         myAssemblyInstaller.UseNewContext = True
         
         ' Clear the 'IDictionary' object.
         mySavedState.Clear()
         
         ' Install the 'MyAssembly_Install' assembly.
         myAssemblyInstaller.Install(mySavedState)
         
         ' Commit the 'MyAssembly_Install' assembly.
         myAssemblyInstaller.Commit(mySavedState)
      Catch
      End Try

   End Sub
End Class

Remarques

Cette méthode appelle la Install méthode de chaque programme d’installation contenue dans la Installers propriété de cette instance. L’objet IDictionary spécifié par le savedState paramètre est mis à jour pour refléter le status de l’installation après l’exécution des programmes d’installation contenus. Si toutes les Install méthodes réussissent, la Commit méthode est appelée. Sinon, la Rollback méthode est appelée.

Notes pour les appelants

Le IDictionary spécifié par le savedState paramètre doit être vide lorsqu’il est passé à la Install(IDictionary) méthode.

S’applique à