Using VSTS Package Management for PowerShell Modules

1 minute read

Scenario

I wanted to store my PowerShell Modules in VSTS and then install those modules during automated Builds / Releases.

Solution

Create a New Feed

  1. Install Package Management in VSTS from the Marketplace.
    This is free for up to 5 users.
  2. Create a feed called psmodules: Create a feed
  3. Once the new feed has been created, click Connect to feed.
  4. Make a note of the Package source URL, eg. https://ACCOUNTNAME.pkgs.visualstudio.com/_packaging/psmodules/nuget/v3/index.json
  5. We need to use a version 2 NuGet feed URL, so change the last part from /v3/index.json to /v2 eg. https://ACCOUNTNAME.pkgs.visualstudio.com/_packaging/psmodules/nuget/v2

Create a Personal Access Token (PAT)

  1. Create a PAT.
  2. Ensure you tick the following Authorized Scopes:
    Packaging (read and write), Packaging (read), Packaging (read, write, and manage).

Select Authorized Scopes for packaging

Register the Repository in PowerShell

Use the Register-VstsFeedForPowerShellRepository.ps1 script I created below, following the comments for required variable changes:

Known Issues

If you install and import the latest version of PowerShellGet (v1.6.0) you may get the following error when you try to use Publish-Module:

Find-Module : A parameter cannot be found that matches parameter name 'AllowPrereleaseVersions'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.6.0\PSModule.psm1:1341 char:37
+             $currentPSGetItemInfo = Find-Module @FindParameters |
+                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Find-Module], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Find-Module

I’m told this will be fixed soon, but in the meantime we can use PowerShellGet v1.5.0.0 which works as expected.

Leave a comment