Set Other Packages Arguments
Packages can fill other packages parameters with values, which allows us to create re-usable packages with multiple parameters, but in the meantime easily set up by the user with few or no parameters to fill.
Lets start by adding a parameter to our app-dependency by editing the CreatePackages.ps1 script:
... $AppDependency = @{ 'Id' = 'app-dependency' 'Name' = 'App Dependency' 'Version' = '1.0' 'InputPath' = @( Join-Path $PSScriptRoot 'app-dependency\*' # Add all files to package from directory. ) 'Parameters' = @( @{ Key = 'ParameterFromPackage'; Description = 'Parameter from Package Id'; DefaultValue = 'No value given'} ) 'OutputDir' = (Join-Path $PSScriptRoot 'Package') 'Commands' = @{ 'Install' = 'Package.psm1:Install-Package' 'Update' = 'Package.psm1:Update-Package' } } ...Next, edit the AddContent function in app-dependency\Package.psm1 script to also log the value of the parameter when run:
... function AddContent($Context, $Keyword) { $LogFile = "c:\temp\$($Context.Package.Id).txt" "$(Get-Date) $Keyword package $($Context.Package.id) $($Context.Package.Version)" | Add-Content -Path $LogFile "Parameter: $($Context.Parameters.ParameterFromPackage)" | Add-Content -Path $LogFile } ...Run, first the CreatePackages.ps1 script and then the installer to see how a new text box with label "Parameter from Package Id" appears on the installer - exit the installer on the users input page.
Next, we add a FillParameter section to the example-app manifest:
$ExampleApp = @{ 'Id' = 'example-app' 'Name' = 'Example App' 'Version' = (Join-Path $PSScriptRoot 'example-app\*.exe') # Version is fetched from the exe file.. 'Commands' = @{ 'Install' = 'Package.psm1:Install-Package' 'Update' = 'Package.psm1:Install-Package' } 'Dependencies' = @{ 'app-dependency' = '1.0' } 'Parameters' = @( (New-UssParameter -Key 'AdditionalComponents' ` -Description "Install Additional Components?" ` -Widget CheckBox -DefaultValue "true") ) 'FillParameters' = @{ 'app-dependency' = @{ 'ParameterFromPackage' = 'example-app' } } 'InputPath' = @( Join-Path $PSScriptRoot 'example-app\*' # Add all files to package from directory. ) 'OutputDir' = (Join-Path $PSScriptRoot 'Package') }Again, run the CreatePackages.ps1 and the installer to see that the text box has now disappeared - complete the install.
Check the log file c:\temp\app-dependency.txt and see the new log message.