Choco install issue with chocolateyinstall.ps1 or nuspec file
Asked Answered
Q

2

6

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
Quietude answered 14/7, 2016 at 14:6 Comment(5)
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>Quietude
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 @packageArgsQuietude
Can you move these comments up to the question so we can see the code better?Burkley
I moved the comments up for you. :DBurkley
I added a comment to the accepted answer that explains the issue betterBurkley
B
7

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.

Burkley answered 16/7, 2016 at 14:44 Comment(2)
The issue is $file, $fileType, and PowerShell's partial parameter name matching - $file does not exist as a parameter in Install-ChocolateyPackage but $fileType does, so due to PowerShell's partial matching, it wires up both $file and $fileType to -FileType and boom, you get that error.Burkley
Took me a minute to see that there was Install-ChocolateyInstallPackage and ChocolateyPackageTurkic
H
1

I was installing Redis and faced a similar issue, i managed to solve it by going to an old version [Deprecated], command :

choco install redis-64

So, the same may work for everyone else by just going to an older version i think.

Helldiver answered 6/9, 2020 at 12:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.