Packing a Powershell script/module to Nuget

Welcome Forums General PowerShell Q&A Packing a Powershell script/module to Nuget

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 5 months ago.

  • Author
  • #80077

    Points: 54
    Rank: Member

    Hi folks,

    I'm setting up an private NuGet server for testing purposes, but want to use it later for a place to get scripts from.

    I don't completely understand how to pack a Powershell file to the NuGet. According to the documentation I need to use either the .nupkg file, which does not contain any references to the script I want to package (Unless I put dependency in there?)
    I can't use the .ps1 extension to pack the file to my understanding. I need to use like the .csproj extension (Which is not created during the Visual Studio Powershell Script creation).
    I get a psproj file if I create it with Visual Studio, but that doesn't seem to work.

    Could anyone direct me towards a resource where it explains how to pack a Powershell script? I've tried to find help articles but to no avail.

  • #80804

    Points: 0
    Rank: Member

    You can use the Publish-* cmdlets, which call into nuget.exe and build the nuspec file (which nuget uses to create the nupkg file) and publish to the gallery. Before you can publish to your private NuGet Server, you need to register it as a repo with Register-PsRepository. Something like this for example:

    Register-PSRepository -Name "TestPsGallery" `
    -ScriptSourceLocation "" `
    -ScriptPublishLocation "" `
    -InstallationPolicy Trusted

    If you want to publish modules, you need to add the SourceLocation and PublishLocation parameters to the Register-PsRepository command. Once your repository is registered, you can use it like any other NuGet repo to publish and install scripts and modules to.

    Publish-Script -Path PathToScript -Repository TestPsGallery -NuGetApiKey ApiKey

  • #80986

    Points: 54
    Rank: Member


    I ended up doing above, however before I read your post. It wasn't very clear that you could do that.


The topic ‘Packing a Powershell script/module to Nuget’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort