locked
MSI Custom Action Order. RRS feed

  • Question

  • Hey,

    I just added an output to some of the methods that can be overridden for an Installer and this is the order the methods are called in.

    [20/02/2013 10:30:26] OnBeforeInstall
    [20/02/2013 10:30:26] OnAfterInstall
    [20/02/2013 10:30:26] Install
    [20/02/2013 10:30:26] OnCommitting
    [20/02/2013 10:30:26] OnCommitted
    [20/02/2013 10:30:26] Commit

    What I don't understand is why "OnAfterInstall" is called before "Install" and why "OnCommitted" is called before "Commit".

    I assumed the order would be like this:

    [20/02/2013 10:30:26] OnBeforeInstall
    [20/02/2013 10:30:26] Install
    [20/02/2013 10:30:26] OnAfterInstall
    [20/02/2013 10:30:26] OnCommitting
    [20/02/2013 10:30:26] Commit
    [20/02/2013 10:30:26] OnCommitted

    Could someone explain why? this is also the same for all 3 of the uninstall methods.

    Thanks

    Edit: Additionally when the "OnBeforeInstall" method is called, the files packaged up have already been extracted? Is there a way to run some custom action code BEFORE the package has been extracted to the destination folder?


    • Edited by Steveiwonder Wednesday, February 20, 2013 10:53 AM
    • Moved by Mike Feng Thursday, February 21, 2013 8:51 PM
    Wednesday, February 20, 2013 10:37 AM

Answers

  • How do you have done the logging? Notice that if you do something like

    public override void Install(IDictionary stateSaver)
    {
        log.Write("Install");
    
        base.Install(stateSaver);
    }
    
    protected override void OnAfterInstall(IDictionary savedState)
    {
        log.Write("After Install");
    
        base.OnAfterInstall(savedState);
    }
    
    protected override void OnBeforeInstall(IDictionary savedState)
    {
        log.Write("Before Install");
    
        base.OnBeforeInstall(savedState);
    }

    then depending on which side of the base.Install(stateSaver) you put the log writing the output is either

    Install
    BeforeInstall
    AfterInstall

    or

    BeforeInstall
    AfterInstall
    Install

    That's because it is the base.Install that calls the OnBeforeInstall and OnAfterInstall so that the logging you have implemented might not give the correct order of the method calls.



    • Edited by MasaSam Wednesday, February 20, 2013 1:07 PM
    • Marked as answer by Steveiwonder Wednesday, February 20, 2013 2:16 PM
    Wednesday, February 20, 2013 1:07 PM

All replies

  • How do you have done the logging? Notice that if you do something like

    public override void Install(IDictionary stateSaver)
    {
        log.Write("Install");
    
        base.Install(stateSaver);
    }
    
    protected override void OnAfterInstall(IDictionary savedState)
    {
        log.Write("After Install");
    
        base.OnAfterInstall(savedState);
    }
    
    protected override void OnBeforeInstall(IDictionary savedState)
    {
        log.Write("Before Install");
    
        base.OnBeforeInstall(savedState);
    }

    then depending on which side of the base.Install(stateSaver) you put the log writing the output is either

    Install
    BeforeInstall
    AfterInstall

    or

    BeforeInstall
    AfterInstall
    Install

    That's because it is the base.Install that calls the OnBeforeInstall and OnAfterInstall so that the logging you have implemented might not give the correct order of the method calls.



    • Edited by MasaSam Wednesday, February 20, 2013 1:07 PM
    • Marked as answer by Steveiwonder Wednesday, February 20, 2013 2:16 PM
    Wednesday, February 20, 2013 1:07 PM
  • That's because it is the base.Install that calls the OnBeforeInstall and OnAfterInstall.

    This makes sense, thanks!

    Any idea about my Edit?

    Edit: Additionally when the "OnBeforeInstall" method is called, the files packaged up have already been extracted? Is there a way to run some custom action code BEFORE the package has been extracted to the destination folder?

    • Edited by Steveiwonder Wednesday, February 20, 2013 2:19 PM
    Wednesday, February 20, 2013 2:16 PM
  • All of the Visual Studio custom actions run after the files have been installed.  As the docs say, "This method is called before the Install methods of the installers in this instance's InstallerCollection are called" but they are still after the files have been installed. You need another tool if you wish to run custom actions before an install. Note that setup projects to build MSI files are being retired anyway.

    http://www.installsite.org/pages/en/msi/authoring.htm


    Phil Wilson

    Monday, February 25, 2013 6:43 PM