Installer.Install(IDictionary) 方法

定义

在派生类中被重写时,执行安装。When overridden in a derived class, performs the installation.

public:
 virtual void Install(System::Collections::IDictionary ^ stateSaver);
public virtual void Install (System.Collections.IDictionary stateSaver);
abstract member Install : System.Collections.IDictionary -> unit
override this.Install : System.Collections.IDictionary -> unit
Public Overridable Sub Install (stateSaver As IDictionary)

参数

stateSaver
IDictionary

IDictionary 用于保存执行提交、回滚或卸载操作所需的信息。An IDictionary used to save information needed to perform a commit, rollback, or uninstall operation.

例外

stateSaver 参数为 nullThe stateSaver parameter is null.

该集合的一个安装程序的 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.

示例

下面的示例演示了 Install 类的方法 InstallerThe following example demonstrates the Install method of the Installer class. 类派生自 Installer 基类, Install 方法被重写。A class is derived from the Installer base class and the Install method is overridden.

   // Override the 'Install' method of the Installer class.
public:
   virtual void Install( IDictionary^ mySavedState ) override
   {
      Installer::Install( mySavedState );
      // Code maybe written for installation of an application.
      Console::WriteLine( "The Install method of 'MyInstallerSample' has been called" );
   }
// Override the 'Install' method of the Installer class.
public override void Install( IDictionary mySavedState )
{
   base.Install( mySavedState );
   // Code maybe written for installation of an application.
   Console.WriteLine( "The Install method of 'MyInstallerSample' has been called" );
}
' Override the 'Install' method of the Installer class.
Public Overrides Sub Install(mySavedState As IDictionary)
   MyBase.Install(mySavedState)
   ' Code maybe written for installation of an application.
   Console.WriteLine("The Install method of 'MyInstallerSample' has been called")
End Sub

继承者说明

-如果在 Install(IDictionary) 派生类中重写方法,请确保 Install(IDictionary) 先在派生方法中调用基类的方法。- If you override the Install(IDictionary) method in a derived class, be sure to call the base class's Install(IDictionary) method first in your derived method. Install(IDictionary)方法调用 Install(IDictionary) 此实例的属性中包含的每个安装程序的方法 InstallersThe Install(IDictionary) method calls the Install(IDictionary) method of each installer contained in the Installers property of this instance. 在包含的安装程序运行后,此方法将更新 IDictionary 通过参数) 指定 (对象, stateSaver 以反映安装的状态。After the contained installers run, this method updates the IDictionary object (specified through the stateSaver parameter) to reflect the status of the installation. IDictionary传递给方法时,应为空 Install(IDictionary)The IDictionary should be empty when passed to the Install(IDictionary) method. 如果所有 Install(IDictionary) 方法均成功,则 Commit(IDictionary) 调用方法。If all the Install(IDictionary) methods succeed, the Commit(IDictionary) method is called. 否则,将 Rollback(IDictionary) 调用方法。Otherwise, the Rollback(IDictionary) method is called.

-如果需要将安装程序实例添加到 Installers 方法中的集合 Install(IDictionary) ,请确保在方法中对集合执行相同的添加 Uninstall(IDictionary)- If you need to add installer instances to the Installers collection in the Install(IDictionary) method, be sure to perform the same additions to the collection in the Uninstall(IDictionary) method. 但是,如果将安装程序实例添加到 Installers 自定义安装程序的类构造函数中的集合,则可以避免在这两种方法中维护该集合。However, you can avoid maintaining the collection in both methods if you add installer instances to the Installers collection in the class constructor for your custom installer.

适用于

另请参阅