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

例外

参数 savedStatenull.

-或-

保存状态 IDictionary 可能已损坏。

-或-

找不到文件。

集合中某个安装程序的事件处理程序中 Committing 发生错误。

-或-

集合中某个安装程序的事件处理程序中 Committed 发生错误。

-或-

安装阶段发生 Commit(IDictionary) 异常。 将忽略异常,并且安装将继续。 但是,安装完成后,应用程序可能无法正常工作。

-或-

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

-或-

无法创建其中一种安装程序类型的实例。

安装阶段发生 Commit(IDictionary) 异常。 将忽略异常,并且安装将继续。 但是,安装完成后,应用程序可能无法正常工作。

示例

以下示例演示AssemblyInstaller类的Install构造函数和CommitAssemblyInstaller方法和方法。

通过调用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中的所有安装程序的方法成功时InstallerCollection,才会调用此方法。 然后,此方法调用 Commit 集合中每个安装程序的方法。

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

适用于