Installing a NuGet Server | Making Module Packages

Package Explorer

The NuGet team created a great GUI tool called Package Explorer for editing packages. Head over to their how to page for a walk-through on installing and using Package Explorer, then come back here to find out how to configure a package for compatibility with PS-NuGet.

PowerShell Modules in PS-NuGet Packages

PS-NuGet tries to borrow as much as possible from the main NuGet projects, where it fits in with our goal of easy module management for PowerShell. The NuGet package specification lists four special folders in a NuGet package. The PS-Nuget package only supports two of those folders, "tools" and "content".

Content

The content folder is where your module code goes. The files (and sub-folders) in this folder get copied directly into your module folder that PS-NuGet is managing. This is where you put your PSD1, PSM1, and any other supporting files your module needs.

Tools

The NuGet package specification defines three PowerShell scripts that act as event handlers for the package lifecycle. Those three scripts have been brought over to the PS-NuGet client as well and are placed in the "tools" folder in your package. All three files are optional (as is the tools folder), depending on your package's needs. The three files are automatically run based on their file names using the following conventions:
  • init.ps1 runs when Install-NuGetPackage is called on a package. This is effectively called only once, as a package is not allowed to be installed on top of itself, although if a package is uninstalled, the init.ps1 script will be run if the package is ever re-installed.
  • install.ps1 runs both when Install-NuGetPackage and Update-NuGetPackage are called on a package.
    • When Install-NuGetPackage is called, init.ps1 runs first and then install.ps1 is run. Both scripts are run AFTER the package files have been extracted.
    • install.ps1 is called again every time Update-NuGetPackage is called. It is run AFTER the package files have been extracted, and thus the version of install.ps1 that is run is the version from the NEW package that was downloaded during the update.
  • uninstall.ps1 runs when Uninstall-NuGetPackage is called on a package.

The right-click context menu in Package Explorer has options to add both a "content" and "tools" folder for you, so you don't have to remember what the correct names are. The right-click context menu on the "tools" folder also has options to add the init, install, and uninstall script files for you. The script files generated by Package Explorer include the correct parameter header for the parameters that are passed to the event scripts as defined here:
  • $InstallPath - Required for init, install, and uninstall
    • The fully qualified path to the folder where the module is installed.
  • $ToolsPath - Required for init, install, and uninstall
    • The fully qualified path to the folder where the tools folder was extracted.
  • $package - Required for init, install, and uninstall
    • Always $null as of right now, but is required to maintain compatibility with the NuGet package specification.
  • $project - Required for install and uninstall
    • Always $null as well, but is required to maintain compatibility with the NuGet package specification

The param blocks look like this

Script Parameters
init.ps1 param($installPath, $toolsPath, $package)
install.ps1 param($installPath, $toolsPath, $package, $project)
uninstall.ps1 param($installPath, $toolsPath, $package, $project)


Special thanks to the Outercurve Foundation for releasing the NuGet Documentation that much of this page came from under the Creative Commons 3.0 License

Last edited Feb 11, 2012 at 5:02 AM by gpduck, version 1

Comments

No comments yet.