4

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.

PhilDW
  • 20,260
  • 1
  • 18
  • 28
Kevin Herrick
  • 413
  • 1
  • 6
  • 16

2 Answers2

2

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.

airafr
  • 332
  • 2
  • 7
1

It depends what you mean by "command line arguments", but I assume you mean property values, as in something like:

msiexec /I [path to your msi] MYPROP1=THIS MYPROP2=THAT

and you want to pass MYPROP1 and MYPROP2 values into the custom action.

So just add your executable as a custom action. In the properties window of the custom action there is an Arguments setting. If you give that a value of:

[MYPROP1];[MYPROP2]

these will be resolved at install time to the actual values and passed into your command line. Use the format that your command line expects to see, such as:

/one=[MYPROP1] /two=[MYPROP2] and so on.

It's not always useful to run apps as custom actions from an Everyone install, primarily because they will run with the local system account and therefore won't have access to the installing user's folders, some databases, the network and so on. If you're configuring something it is often better to run it the first time your app is run, so it will run in a normal interactive user context.

PhilDW
  • 20,260
  • 1
  • 18
  • 28