Search code examples
nugetnuget-packagechocolateyoneget

How do I shim executables with the same names in different directories?


I am creating a Chocolatey package for internal team usage. (In this case, the package is for Microsoft's windows debuggers.)

Windows Debuggers contains two folders, one for 32-bit x86 executables and an x64 folder for 64-bit executables.

The executable names are identical.

x86\adplus.exe
x64\adplus.exe

After installation it looks like the shim created by Chocolatey is indeed starting one of the adplus instances successfully. But sometimes I need the 32-bit version and sometimes I need the 64-bit version.

So here is the question: When there are two identically named executables in different directories, how do I tell Chocolately to create different shims for the executables in each directory?


Solution

  • The short answer is that you can't have two identically named shims in the Chocolatey shim folder ($env:ChocolateyInstall\bin).

    A limitation of Windows for a directory is that each file/folder must be a unique name. This is what you are running into. Shims get dropped into the $env:ChocolateyInstall\bin folder, which puts them on the PATH automatically because $env:ChocolateyInstall\bin is on the PATH (it allows folks to install all kinds of things without overloading the PATH environment variables).

    You can create an empty file ending in .ignore (e.g x86\adplus.exe.ignore) file next to the one you don't want to be shimmed. This is documented on the wiki. You can even do it programmatically during install based on something like OS architecture.

    It sounds like you have a need for one of them sometimes and the other at other times on the SAME machine. I would suggest .ignore files for both files, and likely using Get-BinRoot to push the files to a tools folder (you get to define where the location of this is). Then you can set the process PATH temporarily for whichever one you need and it doesn't persist to the actual path. You can even set one on the path and then override it when you want the other.

    Since the automation scripts are just PowerShell, you have all kinds of options here.