Search Results for

    Show / Hide Table of Contents

    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.

    1. 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'
          }
      }
      ...
      
    2. 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
      
      }
      ...
      
    3. 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.

    4. 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')
      }
      
    5. Again, run the CreatePackages.ps1 and the installer to see that the text box has now disappeared - complete the install.

    6. Check the log file c:\temp\app-dependency.txt and see the new log message.

    In this article
    Back to top Generated by DocFX