Author Posts

September 19, 2017 at 12:11 pm

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.

September 28, 2017 at 7:05 am

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 "http://testpsgallery.net/nuget" `
-ScriptPublishLocation "http://testpsgallery.net/api/v2/package" `
-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

September 29, 2017 at 7:45 pm

Thanks!

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

Cheers