Search code examples
c#custom-actionsetup-deploymentvisual-studio-setup-proje

Pass .msi Args to Install Custom Action


I have a Setup and Deployment project in Visual Studio 2013 that creates an .msi installer for my solution. I also have a C# WinForms app that launches in the Install Custom Action. If a user launches the .msi from the command line, is there any way to pass the command-line arguments to the app that runs during the install custom action?

I know that I can supply the Install Custom Action app arguments using the CustomActionData parameter, so can I somehow dynamically set that to whatever the .msi arguments are? Or is there an easier/better way to do this?

Any help would be appreciated.


Solution

  • You can add an installer class to your app and override the Install method. Then you can access the command-line parameters in the Context.Parameters property.

    [RunInstaller(true)]
    public class CustomInstaller : System.Configuration.Install.Installer
    {
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
            //this.Context.Parameters contains the command line arguments
        }
    }
    

    More information can be found in the documentation.