Creating Packages with Chocolatey

This guide is for merely installing Chocolatey, creating your first package, and testing it locally; by no means is it a thorough guide as Chocolatey is robust and loaded with features, especially the Chocolatey for Business version. I’ll be trying the Business version soon and have more guides, but for now get your feet wet. The link below has all the feature info you need and technical documentation.

Go to https://chocolatey.org/

Open Powershell with administrative rights. On the Chocolatey Install page look for the ‘Install with powershell.exe’ section and copy the command line:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’))

Paste and run the powershell command. Chocolatey will install in less than a minute.

Now you can have some fun installing some applications from the Chocolatey repo. Go to the Packages page of the site (https://chocolatey.org/packages), and choose from the over 6000 packages that have been reviewed, maintained and virus scanned :

Open a command window or powershell as an admin, and type:

Choco install ccleaner -y

The -y is to agree to all prompts.

CCleaner will be installed silently and show in Programs and Features. Chocolatey downloads the application to C:\ProgramData\chocolatey\lib:

If the package allows it, you can also uninstall the app silently by typing:

Choco uninstall ccleaner

If there is a newer version of the app you can type:

Choco upgrade ccleaner

And the latest version will uninstall and install the new silently.

For a full list of options and switches type choco /?

Creating a package

Create a folder on the root of C:\ called Packages. And open an elevated powershell or cmd prompt from this location. Type:

Choco new myping (or whatever the name of your app is). For this demo I’m using MyPingApp by Veles Software.

When you navigate to the Packages folder, you’ll see a new folder called myping

Download the msi from https://www.velessoftware.com/download/ and copy it to the tools folder.

The two files you need to edit are the myping.nuspec file and the chocolateyinstall.ps1.

In the nuspec file edit it as follows:

<?xml version=”1.0″ encoding=”utf-8″?>

<package xmlns=”http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd”>

<metadata>

<id>myping</id>

<version>4.7.9.9</version>

<!– == SOFTWARE SPECIFIC SECTION == –>

<!– This section is about the software itself –>

<title>MyPing (Install)</title>

<authors>Bob Smith</authors>

<tags>myping</tags>

<summary>My Ping App</summary>

<description>To manage domain computers</description>

</metadata>

<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>

</package>

Edit the chocolateyinstall.ps1 file:

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

$fileLocation = Join-Path $toolsDir ‘My Ping App-Setup_4_7_9_9.msi

$packageName = ‘MyPing

$packageArgs = @{

packageName = $packageName

unzipLocation = $toolsDir

fileType = ‘MSI‘ #only one of these: exe, msi, msu

#url = $url

#url64bit = $url64

file = $fileLocation

softwareName = ‘MyPing*‘ #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique

# MSI

silentArgs = “/qn /norestart /l*v `”$($env:TEMP)\$($packageName).$($env:chocolateyPackageVersion).MsiInstall.log`”” # ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=0

validExitCodes= @(0, 3010, 1641)

# OTHERS

# Uncomment matching EXE type (sorted by most to least common)

#silentArgs = ‘/S’ # NSIS

#silentArgs = ‘/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-‘ # Inno Setup

#silentArgs = ‘/s’ # InstallShield

#silentArgs = ‘/s /v”/qn”‘ # InstallShield with MSI

#silentArgs = ‘/s’ # Wise InstallMaster

#silentArgs = ‘-s’ # Squirrel

#silentArgs = ‘-q’ # Install4j

#silentArgs = ‘-s’ # Ghost

# Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence.

#silentArgs = ” # none; make silent with input macro script like AutoHotKey (AHK)

# https://chocolatey.org/packages/autohotkey.portable

#validExitCodes= @(0) #please insert other valid exit codes here

}

Install-ChocolateyInstallPackage

This has been edited so that the app will install locally, and not default to the Chocolatey Repo.

Once editing is complete, from the elevated Powershell or cmd type:

Choco pack

You’ll now see a myping4.7.9.9.nupkg file. This is the created package.

To install the package locally, type:

choco install myping -dv -s . (The period at the end is mandatory)

The app should install silently but if it doesn’t add -y to agree to all prompts.

If the app throws errors then you’ll need to re-examine your file edits. Remember that if you edit the files again, you need to run choco pack again to capture the changes and update the package.

You can also test the uninstall by typing choco uninstall myping.

Again, if you run into any troubles, go to chocolatey.org and search the documentation.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.