Part 2a: Creating a nupkg to distribute a portable package of a ZIPed EXE

Please refer to Building Packages to form the proper template before continuing.


 

Create the Package config:

cd %chocolateyinstall%\chocolateytemplates\_templates
warmup chocolatey Parkdale
cd Parkdale

Edit the package config:
You will edit the nuspec file, which is generally the same as the nuget nuspec specifications, except for the additional “source” parameter.
Beware of common mistakes.

cd %chocolateyinstall%\chocolateytemplates\_templates\Parkdale
notepad Parkdale.nuspec

A few things should already be specified, but we will modify a few other things.

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>Parkdale</id>
    <title>Parkdale</title>
    <version>2.0</version>
    <authors>Steffen Z.</authors>
    <owners>Matt Brown</owners>
    <summary>Parkdale is a read and write benchmark for UNC access devices (including local HDD, servers, etc).</summary>
    <description>Parkdale </description>
    <projectUrl>http://thesz.diecru.eu/content/parkdale.php</projectUrl>
    <tags>Parkdale hdd hard drive test benchmark</tags>
    <copyright>WTFPL (see license URL)</copyright>
    <licenseUrl>http://thesz.diecru.eu/content/license.php</licenseUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <!--<iconUrl>https://raw.github.com/test repo/master/Parkdale/Parkdale.png</iconUrl>-->
    <!--<dependencies>
      <dependency id="" version="" />
    </dependencies>-->
    <releaseNotes>This chocolatey package is configured to install Parkdale.exe to your x86 program files and is compatible with >=XP.  chocolateyInstall.ps1 also creates a shortcut on the start menu.</releaseNotes>
  </metadata>
  <files>
    <file src="tools\**" target="tools" />
    <!--<file src="content\**" target="content" />-->
  </files>
</package>

Create the installation and uninstallation scripts:

Edit the powershell install script:
The chocolateyInstall.ps1 powershell script is what’s executed by chocolatey when an install occurs.
The script helper reference will assist you when dealing with the chocolateyInstall.ps1 powershell script.

cd %chocolateyinstall%\chocolateytemplates\_templates\Parkdale
notepad .\tools\chocolateyInstall.ps1

Make note of some of the interesting things:
1) This is a portable application.
2) It is only available by zip.
3) Because we’re nice, we’ll work out some logic to place parkdale.exe into the program files directory:

$packageName = 'Parkdale' # arbitrary name for the package, used in messages
$url = 'http://thesz.diecru.eu/data/get.php?file=Parkdale.zip' # download url
$url64 = $url # 64bit URL here or just use the same as $url
try {
if ( test-path "$env:ProgramFiles(x86)" ) {
mkdir "$env:programfiles(x86)\Parkdale"
$destdir = "$env:programfiles(x86)\Parkdale"
}
else {
mkdir "$env:programfiles\Parkdale"
$destdir = "$env:programfiles\Parkdale"
}
} catch {
Write-ChocolateyFailure $packageName $($_.Exception.Message)
throw 
}
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$home\start menu\programs\Parkdale.lnk")
$Shortcut.TargetPath = $destdir\Parkdale.exe"
$Shortcut.Save()

Install-ChocolateyZipPackage "$packageName" "$url" "$destdir" "$url64"

Edit the powershell uninstall script:
Although not contained in the template, in order to allow users to utilize the `chocolatey uninstall` command for a package, you must include a `chocolateyUninstall.ps1` script within the package.

cd %chocolateyinstall%\chocolateytemplates\_templates\Parkdale
notepad .\tools\chocolateyUninstall.ps1

There are two helper scripts that are included (as of August), but aren’t really rolled into the main parts of code yet: `Uninstall-ChocolateyPackage.ps1` and `UnInstall-ChocolateyZipPackage.ps1`. So, do not use them (yet).

$packageName = 'Parkdale'
$zipfileName = 'Parkdale.zip'
try {
if ( test-path "$env:ProgramFiles(x86)" ) {
$destdir = "$env:programfiles(x86)\Parkdale"
}
else {
$destdir = "$env:programfiles\Parkdale"
}
remove-item $destdir\parkdale.exe -force -erroraction silentlycontinue
remove-item "$home\start menu\programs\Parkdale.lnk" -force -erroraction silentlycontinue
Write-ChocolateySuccess $packageName
} catch {
Write-ChocolateyFailure $packageName $($_.Exception.Message)
throw
}

Build the package:
All packages are a nuget package (nupkg). Chocolatey includes a batch to build nuget packages:

cd %chocolateyinstall%\chocolateytemplates\_templates\Parkdale
cpack

Test the package install:
Without getting too complex with nuget.server asp.net instances, you can simply use any directory that is accessible (including anything accessible via a device redirector, like CIFS, NFS, etc):

mkdir %systemdrive%\nupkgs
cd %chocolateyinstall%\chocolateytemplates\_templates\Parkdale
copy Parkdale.*.nupkg %systemdrive%\nupkgs\
cd %userprofile%
chocolatey list -source '%systemdrive%\nupkgs'
chocolatey search hdd -source '%systemdrive%\nupkgs'
chocolatey search hdd benchmark -source '%systemdrive%\nupkgs'
pause
chocolatey -debug install Parkdale -source '%systemdrive%\nupkgs'
pause
chocolatey version all -lo

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: