共用方式為


AssemblyInstaller.Install(IDictionary) 方法

定義

執行安裝。

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,用來儲存執行認可、復原或解除安裝作業所需的資訊。

例外狀況

savedState 參數為 null

-或-

無法找到檔案。

在集合中有一個安裝程式的 BeforeInstall 事件處理常式發生例外狀況。

-或-

在集合中有一個安裝程式的 AfterInstall 事件處理常式發生例外狀況。

-或-

在其中一個組件中無法找到安裝程式型別。

-或-

無法建立其中一個安裝程式型別的執行個體。

範例

下列範例示範 類別的AssemblyInstallerAssemblyInstaller構函式和 InstallCommit 方法。

叫用AssemblyInstaller建構函式會建立 類別的物件AssemblyInstaller。 已設定此物件的屬性, Install 並呼叫 和 Commit 方法來安裝 『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

備註

這個方法會 Install 呼叫這個實例的 屬性中包含的 Installers 每個安裝程式方法。 參數 IDictionarysavedState 指定的物件會更新,以反映執行自主安裝程序之後安裝的狀態。 如果所有 Install 方法都成功,則會 Commit 呼叫 方法。 否則會 Rollback 呼叫 方法。

給呼叫者的注意事項

IDictionary傳遞至 Install(IDictionary) 方法時,savedState參數所指定的 應該為空白。

適用於