Swoogan
Swoogan

Reputation: 5558

How do I reference the package version in chocolateyinstall.ps1?

I am packaging an existing installer with Chocolatey. The installer has the format <appname>-<version>.exe where version is, for example, 1.0.0. I am using Install-ChocolateyInstallPackage, but I don't know how to reference the installer. I am using $version$ in the nuspec to include the file in the package.

Is there a way to get the version in the install/uninstall script, or do I have to do something like gci .\Application-*.exe to get the full path?

Upvotes: 3

Views: 1418

Answers (1)

ferventcoder
ferventcoder

Reputation: 12561

If the installer version matches the nuspec <version />, you can use the ChocolateyPackageVersion environment variable. See https://chocolatey.org/docs/helpers-reference#variables for the full list.

Package Creation Recommendations

FOSS

It's best if you use choco new pkgid when creating packages. It is going to set everything up for you and save you quite a bit of time as it brings quite a bit of what we call "just in time" documentation. Some parts of your question are answered already when you run choco new, plus it sets you up for success. For instance, your next question will be "Why can't I use .\Application-*.exe in the package scripts?" We recommend you use $toolsDir\Application-*.exe, and when you run choco new, you will see what $toolsDir is set to (for clarity, you will need to have the $toolsDir variable created locally and set in the package script).

Pro - Package Builder UI

Chocolatey Pro (for individuals) has Package Builder UI (minus auto-detection), that can allow you to have a nice interface to use in package creation. It will give you all of the elements of choco new pkgid, but also quite a bit more out of the gate.

Business - Package Builder (w/auto-detection)

Chocolatey for Business (C4B) comes with Package Builder (both CLI with choco new --file installer.exe and Package Builder UI). Package Builder does auto-detection on the actual installer (MSI, EXE, 7Z, ZIP, MSP, MSU) to generate a fully ready to go unattended deployment (package) in about 5-10 seconds. It supports right click and create package.

https://chocolatey.org/docs/features-create-packages-from-installers

Upvotes: 2

Related Questions