In the first article, we saw how to install Chocolatey and used an already available package named "visualstudiocode".

In this article, we will see how to create a custom Chocolatey package using PowerShell.

Run the below command to create a new Chocolatey package:

The folder structure is as follows:

Update bob.nuspec file as shown below:

<?xml version="1.0" encoding="utf-8"?>
    <title>bob (Install)</title>
    <!-- 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" />-->

Update chocolateyinstall.ps1 as shown below. Download the notepad.exe and copy the exe inside the tools folder.

$ErrorActionPreference = 'Stop'; # stop on all errors
$packageName= 'bob'
$toolsDir   = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$url        = ''
$url64      = ''
$fileLocation = Join-Path $toolsDir 'npp.6.9.2.Installer.exe'
$packageArgs = @{
  packageName   = $packageName
  unzipLocation = $toolsDir
  fileType      = 'exe' #only one of these: exe, msi, msu
  url           = $url
  url64bit      = $url64
  file         = $fileLocation
  softwareName  = 'bob*'
  checksum      = ''
  checksumType  = 'md5'
  checksum64    = ''
  checksumType64= 'md5'
  silentArgs    = "/qn /norestart /l*v `"$($env:TEMP)\$($packageName).$($env:chocolateyPackageVersion).MsiInstall.log`""
  validExitCodes= @(0, 3010, 1641)

Run the command choco pack to create a chocolatey package as shown:

Run the command choco install "nameofthepackage" to install the package.

See Also