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 事件处理程序发生异常。

- 或 -

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

- 或 -

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

示例

下面的示例演示 类的 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

注解

此方法调用 Install 此实例的 属性中包含的 Installers 每个安装程序的方法。 参数 IDictionary 指定的 savedState 对象将更新,以在包含的安装程序运行后反映安装状态。 如果所有方法都 Install 成功,则 Commit 调用 方法。 否则, Rollback 将调用 方法。

调用方说明

IDictionary传递给 Install(IDictionary) 方法时, savedState 参数指定的 应为空。

适用于