0

I'm trying to create a self-contained chocolatey package containing a .bat file (i.e. my "executable") that I want to shim onto the path. My chocolateyinstall.ps1 file consists of the following:

    $ErrorActionPreference = 'Stop'; # stop on all errors

    $toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"

    Install-BinFile -Name 'test.bat' -Path $toolsDir

This creates the file test.bat.exe when the package is installed. But when I run the .exe file I get the error:

Cannot find file at '..\lib\test-pkg\tools' (C:\ProgramData\chocolatey\lib\test-pkg\tools). This usually indicates a missing or moved file.

The directory mentioned (C:\ProgramData\chocolatey\lib\test-pkg\tools) definitely exists and contains the test.bat file, so the packaging and installation of the .bat file worked. As such, it looks to be a problem with the shim?

By way of experiment, I tried to shim a .ps1 Powershell script in the same way, and got the same error message.

What am I missing here? Thanks!

Justin
  • 1,980
  • 1
  • 16
  • 25

1 Answers1

1

The problem is the -Path parameter should have the full path to the bat file and not just to the $toolsDir, so something like this would work:

Install-BinFile -Name 'test.bat' -Path "$toolsDir\test.bat"

The surprising implication is that the shim target need not exist for the Install-BinFile to run without error.

Justin
  • 1,980
  • 1
  • 16
  • 25