Vagrant Install-ChocolateyInstallPackage:无法识别 $File 参数

Vagrant Install-ChocolateyInstallPackage: $File parameter not recognized

我正在创建自己的 chocolatey 软件包,并且我正在使用 Install-ChocolateyInstallPackge 进行软件安装。根据其文档,此函数采用 HashTable 将参数传递给它的参数。我有以下几个:

 #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....

但是,我收到一个错误:

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

可以看出,我已经明确指定了exe文件的填充路径

如果我将 File 参数直接指定给函数,它会起作用:

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

我哪里漏了,谁能指出来吗?

由于您使用的是 PowerShell 参数的“splatting”,因此在实际使用 packageArgs 变量时必须使用略有不同的语法。

你应该这样做:

Install-ChocolateyInstallPackage @packageArgs

而不是:

Install-ChocolateyInstallPackage $packageArgs

看这里:

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

完整示例。