Choco install issue with chocolateyinstall.ps1 or nuspec file

Steve Hong picture Steve Hong · Jul 14, 2016 · Viewed 9.4k times · Source

I am trying to create a Chocolatey package and was able to "choco pack" and "choco push" to a local chocolatey.server (simple server) repository. I have configured my C:\ProgramData\Chocolatey\config\chocolatey.config to point to my local chocolatey.server URL. When I try to run

choco install test1

I get the following error:

The package test1 wants to run 'chocolateyinstall.ps1'. Note: If you don't run this script, the installation will fail. Note: To confirm automatically next time, use '-y' or consider setting 'allowGlobalConfirmation'. Run 'choco feature -h' for more details. Do you want to run the script?([Y]es/[N]o/[P]rint): Y

ERROR: Cannot bind parameter because parameter 'file' is specified more than once. To provide multiple values to parameters that can accept multiple v alues, use the array syntax. For example, "-parameter value1,value2,value3". The install of nimatest was NOT successful. Error while running 'C:\ProgramData\chocolatey\lib\test1\tools\chocolateyinstall.ps1'. See log for details.

Chocolatey installed 0/1 packages. 1 packages failed. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Failures - test1 (exited -1) - Error while running 'C:\ProgramData\chocolatey\lib\test1\tools\chocolateyinstall.ps1'. See log for details.

In my test.nuspec I have the following:

<files>
  <!-- This section controls what actually gets packaged into the Chocolatey package -->
  <file src="tools*" target="tools" />
  <!-- Building from Linux? You may need this instead: <file src="tools/*" target="tools" /> -->
</files>

In my chocolateyinstall.ps1 I have:

$ErrorActionPreference = 'Stop';
$packageName= 'Test1'
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$fileLocation = Join-Path $toolsDir 'Test1.exe'

$packageArgs = @{
  packageName = $packageName
  fileType = 'exe'
  file = $fileLocation
  silentArgs = "/SP"
  validExitCodes= @(0, 3010, 1641)
  softwareName = 'Test1*'
  checksum = ''
  checksumType = 'md5'
  checksum64 = ''
  checksumType64 = 'md5'
}

Install-ChocolateyPackage @packageArgs

Answer

ferventcoder picture ferventcoder · Jul 16, 2016

The Error

The error is telling you that you specified the file parameter more than once, which means you likely had one of the following:

  • had file listed twice in your $packageArgs
  • have specified fileType and file and called Install-ChocolateyPackage, which only has filetype (but PowerShell passes both parameters to filetype due to partial parameter name matching)
  • passed both @packageArgs and file as an argument

We've added this issue to https://chocolatey.org/docs/troubleshooting.

You may be experiencing other errors now if you've resolved that aspect. See the next section to understand why.

The Code

You are trying to pass arguments for Install-ChocolateyInstallPackage, not Install-ChocolateyPackage.

If you follow the links you will note the differences that Install-ChocolateyInstallPackage is for locally embedded or UNC share binaries, where Install-ChocolateyPackage is for pulling remote resources.

Creating Packages Recommendation

When you create packages, we highly suggest you use choco new (from the latest released version of Chocolatey) as it generates the packaging that has documentation of the differences already included in the generated chocolateyInstall.ps1. We call this "just in time documentation".

While it appears you did use choco new based on your code, I just wanted to add that the latest version will provide the most beneficial documentation regarding creating packages.