Search code examples
powershellvagrantpackage-managerschocolatey

Vagrant Install-ChocolateyInstallPackage: $File parameter not recognized


I am creating my own chocolatey package and I am using Install-ChocolateyInstallPackge for software installation. According to its documentation, this function takes a HashTable to pass arguments to its parameters. I have the following ones:

 #File:  chocolateyInstall.ps1
 $ErrorActionPreference="stop"
 $toolsDir = $(Split-Path -parent $MyInvocation.MyCommand.Definition)
 $installFile = Join-Path $toolsDir "jdk8u211windowsx64.exe" # JDK.exe is in parent
 ....
 $packageArgs = @{
    PackageName    = 'jdk8da'
    FileType       = 'exe'
    SoftwareName   = 'JDK8*'
    File           = $installFile
    SilentArgs     = '/s ADDLOCAL="ToolsFeature" INSTALLDIR=C:\JAVA'
    ValidExitCodes = @(0)
 }

 Install-ChocolateyInstallPackage $packageArgs

 .... #Setting Environment Variables....

However, I am getting an error:

ERROR: Package parameters incorrect, either File or File64 must be specified

As it can be seen that I have clearly specified the exe file with fill path.

It works if I specify the File parameter direct to the function:

Install-ChocolateyInstallPackage -PackageName "JDK8" -FileType "exe" -File $installFile ....

Where am I missing, can anyone point that out please?


Solution

  • Due to the fact that you are using “splatting” of the PowerShell parameters, you have to use a slightly different syntax when actually using the packageArgs variable.

    You should be doing this:

    Install-ChocolateyInstallPackage @packageArgs
    

    Rather than:

    Install-ChocolateyInstallPackage $packageArgs
    

    Have a look here:

    https://github.com/chocolatey-community/chocolatey-coreteampackages/blob/master/automatic/calibre/tools/chocolateyInstall.ps1

    For a complete example.