AssemblyInstaller.Commit(IDictionary) 方法

定义

完成安装事务。

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

参数

savedState
IDictionary

IDictionary,它包含安装程序集合中所有安装程序都运行后计算机的状态。

例外

savedState 参数为 null

- 或 -

保存的状态 IDictionary 可能已损坏。

- 或 -

未能找到文件。

该集合中的一个安装程序的 Committing 事件处理程序出现错误。

- 或 -

该集合中的一个安装程序的 Committed 事件处理程序出现错误。

- 或 -

在安装的 Commit(IDictionary) 阶段发生异常。 该异常被忽略,安装继续进行。 但是,安装完成后应用程序可能无法正常工作。

- 或 -

在一个程序集中未找到安装程序类型。

- 或 -

未能创建一个安装程序类型的实例。

在安装的 Commit(IDictionary) 阶段发生异常。 该异常被忽略,安装继续进行。 但是,安装完成后应用程序可能无法正常工作。

示例

下面的示例演示 类的 AssemblyInstaller 构造函数和 InstallCommit 方法 AssemblyInstaller

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

注解

仅当此实例InstallerCollection中所有安装程序的方法都成功时Install,才会调用此方法。 然后, Commit 此方法调用集合中每个安装程序的 方法。

将执行正确卸载操作所需的任何信息存储在已保存状态 中,该状态 IDictionary将传递给 Uninstall 方法。

适用于