Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original
Este tópico ainda não foi avaliado como - Avalie este tópico

Installer Classe

Fornece a base para instalações personalizadas.

Namespace:  System.Configuration.Install
Assembly:  System.Configuration.Install (em System.Configuration.Install. dll)
public class Installer : Component

This is the classe base for Tudo personalizado instTudoers in the .NET Framework.Instaladores são componentes que ajudam instalar aplicativos em um computador.

There are several steps you must follow to use an Installer :

  • Inherit the Installer class.

  • Override the Install, Commit, Rollback, and Uninstall methods.

  • Add the RunInstallerAttribute to your derived class and set it to true.

  • Colocar sua classe derivada no conjunto de módulos (assembly) com seu aplicativo para instalar.

  • Chame os instaladores.Por exemplo, usar o InstallUtil.exe para invocar os instaladores.

The Installers property contains a collection of installers.If this instance of Installer is part of an installer collection, the Parent property is set to the Installer instance that contains the collection.For an example of the use of the Installers collection, see the AssemblyInstaller class.

The Install, Commit, Rollback, and Uninstall methods of the Installer class go through the collection of installers stored in the Installers property, and invokes the corresponding method of each installer.

The Install, Commit, Rollback, and Uninstall methods are not always called on the same Installer instance.For example, one Installer instance might be used while installing and committing an application, and then the reference to that instance is released.Later, uninstalling the application creates a reference to a new Installer instance, meaning that the Uninstall method is called by a different instance of Installer.For this reason, in your classe derivada, not Salvar the estado of a computador in an instalador.Instead, use an IDictionary that is preserved across calls and passed into your Install, Commit, Rollback, and Uninstall methods.

Two situations illustrate the need to save information in the state-saver IDictionary.Em primeiro lugar, vamos supor que o instalador define uma chave do Registro.It should save the key's original value in the IDictionary.If the instalação is rolled Voltar, the original valor can be Restored.Em segundo lugar, vamos supor que o instalador substitui um arquivo existente.Save the existing file in a temporary directory and the location of the new location of the file in the IDictionary.If the is rolled , newer the is Deleted and replaced by the original from the Temporário .

The Installer.Context property contains information about the installation.For example, information about the location of the log file for the installation, the location of the file to save information required by the Uninstall method, and the command line that was entered when the installation executable was run.

The following example demonstrates the use of the Installer class.It creates a class which inherits from Installer.When Commit is about to complete, Committing event occurs and a message is displayed.

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;

// Set 'RunInstaller' attribute to true.
[RunInstaller(true)]
public class MyInstallerClass: Installer
{
   public MyInstallerClass() :base()
   {
      // Attach the 'Committed' event.
      this.Committed += new InstallEventHandler(MyInstaller_Committed);
      // Attach the 'Committing' event.
      this.Committing += new InstallEventHandler(MyInstaller_Committing);

   }
   // Event handler for 'Committing' event.
   private void MyInstaller_Committing(object sender, InstallEventArgs e)
   {
      Console.WriteLine("");
      Console.WriteLine("Committing Event occured.");
      Console.WriteLine("");
   }
   // Event handler for 'Committed' event.
   private void MyInstaller_Committed(object sender, InstallEventArgs e)
   {
      Console.WriteLine("");
      Console.WriteLine("Committed Event occured.");
      Console.WriteLine("");
   }
   // Override the 'Install' method.
   public override void Install(IDictionary savedState)
   {
      base.Install(savedState);
   }
   // Override the 'Commit' method.
   public override void Commit(IDictionary savedState)
   {
      base.Commit(savedState);
   }
   // Override the 'Rollback' method.
   public override void Rollback(IDictionary savedState)
   {
      base.Rollback(savedState);
   }
   public static void Main()
   {
      Console.WriteLine("Usage : installutil.exe Installer.exe ");
   }
}


import System.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.Configuration.Install.*;

// Set 'RunInstaller' attribute to true.
/** @attribute RunInstaller(true)
 */
public class MyInstallerClass extends Installer
{
    public MyInstallerClass()
    {
        // Attach the 'Committed' event.
        this.add_Committed(new InstallEventHandler(MyInstaller_Committed));

        // Attach the 'Committing' event.
        this.add_Committing(new InstallEventHandler(MyInstaller_Committing));
    } //MyInstallerClass

    // Event handler for 'Committing' event.
    private void MyInstaller_Committing(Object sender, InstallEventArgs e)
    {
        Console.WriteLine("");
        Console.WriteLine("Committing Event occured.");
        Console.WriteLine("");
    } //MyInstaller_Committing

    // Event handler for 'Committed' event.
    private void MyInstaller_Committed(Object sender, InstallEventArgs e)
    {
        Console.WriteLine("");
        Console.WriteLine("Committed Event occured.");
        Console.WriteLine("");
    } //MyInstaller_Committed

    // Override the 'Install' method.
    public void Install(IDictionary savedState)
    {
        super.Install(savedState);
    } //Install

    // Override the 'Commit' method.
    public void Commit(IDictionary savedState)
    {
        super.Commit(savedState);
    } //Commit

    // Override the 'Rollback' method.
    public void Rollback(IDictionary savedState)
    {
        super.Rollback(savedState);
    } //Rollback

    public static void main(String[] args)
    {
        Console.WriteLine("Usage : installutil.exe Installer.exe ");
    } //main
} //MyInstallerClass


Quaisquer membros públicos estático (compartilhados na Visual Basic) desse tipo são Thread seguro. Não há garantia de que qualquer membro de instância seja isento de segmentos.
Isso foi útil para você?
(1500 caracteres restantes)

Contribuições da comunidade

ADICIONAR
A Microsoft está realizando uma pesquisa online para saber sua opinião sobre o site do MSDN. Se você optar por participar, a pesquisa online lhe será apresentada quando você sair do site do MSDN.

Deseja participar?
© 2013 Microsoft. Todos os direitos reservados.