Day 25: Creating a OneGet Package

Welcome to Day 25 of the “100 Days of DevOps with PowerShell” – we are a quarter of the way through our series! For background on our goals in these articles, see Announcing the “100 Days of Devops with PowerShell” Series here at SCC.

Disclaimer: The code below is from PowerShell 5.0 CTP release and could change or break when RTM is released.  I’ll endeavour to update this article where applicable.

When OneGet was first released along with the Windows Management Framework 5.0 back in April 2014, the only package source was Chocolatey.  Microsoft have said that additional package providers will be available when the product RTMs.  But for now our OneGet package will actually be a Chocolatey package.  For more information on OneGet and discovering and installing packages, please review Day 11 of this series.

In this example we are going to create a Chocolatey package for the System Center 2012 Configuration Manager Support Center, a support tool that helps in gathering data about a  Configuration Manager 2012 environment and ease the troubleshooting process.

Getting Started

The first thing we need to do is install Chocolatey.  Next create a folder to store details about the package we are creating and then finally onto the package detail itself.  The package details are initially stored in a nuspec file which is the manifest file used by NuGet to describe the package.  In the example below I’ve split out the details from the xml file so the values can be entered as script variables.

Also note in the nuspec file we’ve specified that this package has a dependency upon .Net 4.5.2.  By specifying the package name (“DotNet4.5.2”) it will be installed automatically.

The last part of the script downloads the template file ChocolateyInstall.ps1 file, which provides the parameters needed to perform a silent installation as well as the location where the source file is downloaded from.  This file has a lot of information in it initially and to keep things simple I’ve only left the in the lines actually required.

Once the ChocolateyInstall.ps1 file has been edited, we are ready to create the NuGet package file and for this we’re using a Chocolatey command that will do this for us.  Within the C:\Packages\CMSupportCenter folder either run ‘cpack’ on its own or you can provide the path to the nuspec file:

RunCpack

As you can see above we’ve successfully created our nuget package: CMSupportCenter.1.1.1000.nupkg.  The final step is to upload the package to the Chocolatey repository and for that we can use the cpush command.  Before running this command you need to save your APIKey, which is detailed here.

To upload the package we can now run cpush .\CMSupportCenter.1.1.1000.nupkg. and it will be uploaded to the Chocolatey site.

CPush

Our original goal here was to create a ‘OneGet’ package, so now lets see if we can find the package from OneGet:

FindPackage

Conclusion

When the final version of PowerShell 5.0 and OneGet is released the process for creating packages will likely change and not have such a big dependency upon Chocolatey packages.  The concepts however, will remain the same in that ultimately NuGet packages will need to be created.  I hope I’ve demonstrated that that process is not too daunting for somebody new to this area of packaging.

Leave a Reply