Add Package Parameters
A package can have parameters that allow configuration at install time. The parameters are prompted to the user when running the installer or can be passed to the Install-UssPackage
cmdlet.
Lets add a parameter to our package example-app that allows the user to install additional components.
From the previous how-to, lets extend the example-app manifest and add a new property called Parameters, while also bumping the version to 3.0:
... $ExampleApp = @{ 'Id' = 'example-app' 'Name' = 'Example App' 'Version' = '3.0' 'Commands' = @{ 'Install' = 'Package.psm1:Install-Package' 'Update' = 'Package.psm1:Install-Package' 'Remove' = 'Package.psm1:Remove-Package' } 'Dependencies' = @( @{ Id = 'app-dependency'; Version = $AppDependency.Version } ) 'Parameters' = @( @{ Key = 'AdditionalComponents'; Description = 'Install Additional Components?'; Widget = 'CheckBox'; DefaultValue = 'true'} ) 'InputPath' = @( Join-Path $PSScriptRoot 'example-app\*' # Add all files to package from directory. ) 'OutputDir' = (Join-Path $PSScriptRoot 'Package') } ...
We added a new section or property called Parameters, assigned it with a list containing one parameter. This parameter is prompted to the user, with the Description "Install Additional Components?" and a checkbox (Widget, see available widgets here), checked by default. During installation the parameter is accessible in the install script by it's Key AdditionalComponents.
Now, lets change the package script to act on the new parameter we just defined, edit the package script example-app\Package.psm1 as following:
function Install-Package($Context) { # Check if we should install additional components: $Components = ""; if ($Context.Arguments.AdditionalComponents) { $Components = "AdditionalComponents" } # Path to the setup file during execution: $SetupExe = Join-Path $Context.TemporaryDirectory 'Example App.exe' # Execute the setup file with silent parameters: & $SetupExe /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /COMPONENTS="$Components" | Out-Null # Check if the execution was successfull, else throw an error which Update Service will act on: if ($LastExitCode -ne 0) { throw 'Error occured while installing Example App.exe' } }
The installer executable accepts a command line parameter /COMPONENTS="" (as stated in Inno Setup documentation), which we have added here depending on if the user check our new check box on the installer.
Replace the Exemple App.exe in example-app directory with a new 3.0 version.
- Run the CreatePackages.ps1 to re-create and import the package.
- Remove the package if it's already installed.
- Install the package with the installer to see the new parameter prompt during installation.