Saturday, August 1, 2015

Setup your Chocolatey repository in Azure - Part 2

In the first part of this series we've seen how we can have our chocolatey repository hosted on Azure, we can start pushing and using some packages from the server.

To create and publish packages you’ll need nuget executable on your workstation. You can download the nuget.exe from the link

The next step is to create a nuspec file with the details of the package you want to create. In this sample I’ll create a nuspec file for creating a package for the Foxe XML editor and push that to the chocolatey repository.

Create a folder foxe-package in your workstation and add the nuspec file with the contents as given below.

xml version="1.0" encoding="utf-8"?>
<package xmlns:xsd="" xmlns:xsi="">
    <metadata xmlns="">
        <title>Firstobject's free XML editor for Windows</title>
        <description>Free XML editor for Windows</description>
          It loads big files (multi-megabyte) fast and lets you format XML and edit HTML and any loosely formed XML or other markup.
          The tree view is editable and customizable for useful navigation.
        <tags>XML, Windows, Free, Tools, Editor</tags>       

Now create a Tools folder under the foxe-package folder and add a chocolateyinstall.ps1 file with the contents

Install-ChocolateyPackage 'Foxe' 'exe' '/quiet' ''

This will download the installer from the url mentioned in the script and install it on the workstation. We've use the Install-ChocolateyPackage command to run the installer downloaded from the FirstObject website. You can also make use of other commands available to further customize your installation process. For a full list of commands refer the wiki here 

After creating the nuspec file, we’ll use the pack command of the nuget executable to create a nupkg file that will be pushed to the repository.

PS C:\Packages\foxe-package> .\nuget.exe pack .\Foxe.nuspec
Attempting to build package from 'Foxe.nuspec'.
Successfully created package 'C:\Packages\foxe-package\Foxe.1.2.0.nupkg'.

WARNING: 1 issue(s) found with package 'Foxe'.

Issue: Unrecognized PowerShell file.
Description: The script file 'tools\chocolateyinstall.ps1' is not recognized by NuGet and hence will not be executed during installation of this package
Solution: Rename it to install.ps1, uninstall.ps1 or init.ps1 and place it directly under 'tools'.

Now we have the package ready, lets push this to our chocolatey repository

PS C:\Scripts\Chocolatey> .\nuget.exe push .\Foxe.1.2.0.nupkg "YOUR_API_KEY" -s
Pushing Foxe 1.2.0 to ''...
Your package was pushed.

You can list the packages available on the server by using the list command, to verify the packages available.

PS C:\Scripts\Chocolatey> .\nuget.exe list -s -allversions
Foxe 1.0.0
Foxe 1.1.0
Foxe 1.2.0

Next we can try to install this package using chocolatey on the workstation. For installation, open PowerShell as Administrator and execute the command

iex ((new-object net.webclient).DownloadString(''))
and press enter. This will install Chocolatey on the machine.

Now you can use the choco command to install the package from the server as given below.

Next we’ll use PowerShell PackageManagement which is a unified interface to package management systems to make Software Discovery, Installation and Inventory (SDII) work via a common set of cmdlets. We’ll add this repository to the OneGet sources and install packages from here. That's in the next post.

No comments: