powershellnugetonegetpowershellget

Create pure powershell Nuget module for PowerShellGet


What I want

I want to publish number of PowerShell scripts as Nuget package to be used on build systems.

I want to use PowerShellGet to do installation work for me and version management.

I don't want those scripts to be part of any Visual Studio solution, but as standalone scripts.

Usage scenario

On any system, with configured Nuget provider user executes:

Install-Module MyModule

From that moment all exports from that module permanently available for this user. Also user can call that command again to update version of those scripts.

What I've done

You can find current state of package here: GitHub

  1. I've added and configured Nuget provider to our local Nuget server

    To do this call Get-PackageProvider -Name NuGet -ForceBootstrap and Set-PSRepository -Name My_Nuget_Repo -SourceLocation http://my-nuget/api -InstallationPolicy Trusted

  2. Created proper module, which can be imported locally by Import-Module

  3. Created and published Nuget package with that module

Problem

I can install that package by Install-Module cmdlet and I can see it later in Get-InstalledModule list.

But, no functions are available.

Also, no matter what, but Install-Module not calling any of scripts from my package:

(Same package works properly when installed from Visual Studios Install-Package MyModule, scripts are called, PowerShell module is imported).

Investigation

Since PowerShellGet is based on OneGet it seems that problem is in Install-Package cmdlet (which is called inside Install-Module cmdlet).

When I'm executing Install-Package MyModule from Visual Studio Install.ps1 and Init.ps1 are called. But same command from pure PowerShell doing nothing.


Solution

  • After long reverse engineering I've found the root cause

    Technical reason

    Magical tag PSModule has to be added to <Tags> in nuspec file.

    Real reason

    You shouldn't create nuspec file and pack nuget package manually at all. Use Publish-Module cmdlet instead.

    How to do it properly

    I've updated powershellget-module GitHub with:

    Check it out.