AssemblyInstaller.Install(IDictionary) 方法

定義

執行安裝。Performs the 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)

參數

savedState
IDictionary

IDictionary,用來儲存執行認可、還原或解除安裝作業所需的資訊。An IDictionary used to save information needed to perform a commit, rollback, or uninstall operation.

例外狀況

savedState 參數為 nullThe savedState parameter is null.

-或--or- 無法找到檔案。A file could not be found.

在集合中有一個安裝程式的 BeforeInstall 事件處理常式發生例外狀況。An exception occurred in the BeforeInstall event handler of one of the installers in the collection.

-或--or- 在集合中有一個安裝程式的 AfterInstall 事件處理常式發生例外狀況。An exception occurred in the AfterInstall event handler of one of the installers in the collection.

-或--or- 在其中一個組件中無法找到安裝程式型別。Installer types were not found in one of the assemblies.

-或--or- 無法建立其中一個安裝程式型別的執行個體。An instance of one of the installer types could not be created.

範例

下列範例示範的是AssemblyInstaller方法, Install以及AssemblyInstaller類別Commit的和方法。The following example demonstrates the AssemblyInstaller constructor and the Install and Commit methods of the AssemblyInstaller class.

AssemblyInstaller類別的物件是藉由叫用此AssemblyInstaller函式來建立的。An object of the AssemblyInstaller class is created by invoking the AssemblyInstaller constructor. 已設定這個物件的屬性,並Install呼叫和Commit方法來安裝 ' MyAssembly_Install ' 元件。The properties of this object are set and the Install and Commit methods are called to install the 'MyAssembly_Install.exe' assembly.

#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

備註

這個方法會呼叫Install包含Installers在這個實例之屬性中的每個安裝程式的方法。This method calls the Install method of each installer contained in the Installers property of this instance. savedState參數IDictionary所指定的物件會在包含的安裝程式執行之後更新,以反映安裝的狀態。The IDictionary object specified by the savedState parameter is updated to reflect the status of the installation after the contained installers have run. 如果所有Install方法都成功Commit ,則會呼叫方法。If all the Install methods succeed, the Commit method is called. 否則, Rollback會呼叫方法。Otherwise, the Rollback method is called.

給呼叫者的注意事項

傳遞IDictionaryInstall(IDictionary)方法時savedState ,參數所指定的應該是空的。The IDictionary specified by the savedState parameter should be empty when passed to the Install(IDictionary) method.

適用於