Forked from gwalkey/gist:b168d532b472333e96663cf607bf84eb
Created
May 26, 2023 00:36
-
-
Save rvrsh3ll/78739132045f7a58a6428830f44cdec4 to your computer and use it in GitHub Desktop.
Create a NuGet Package to Install a Powershell Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Download the CLI Version of NuGet | |
https://dist.nuget.org/win-x86-commandline/latest/nuget.exe | |
--Create Work Paths | |
md c:\nuget | |
md c:\nuget\source | |
md c:\nuget\publish | |
-- One-Time - Create local NuGet Repo/feed using a local drive path | |
cd c:\nuget | |
Register-PSRepository -Name Local_Nuget_Feed -SourceLocation C:\Nuget\publish -PublishLocation c:\Nuget\publish -InstallationPolicy Trusted | |
(To Remove: Unregister-PSRepository -Name Local_Nuget_Feed) | |
--- Verift/Show all PS Repository | |
Get-PSRepository | |
-- Create Prep folder for your New NuGet Package | |
cd c:\nuget\source | |
md MyModuleName | |
Copy MyModuleName.PSD1 and MyModuleName.PSM1 files from your dev location to here (c:\nuget\source\MyModuleName) | |
-- Edit your Powershell Module Manifest .psd1 File | |
Set the RootModule to the name of your Module.psm1 file | |
Set the ModuleVersion | |
--- Create and Install your Powershell Module as a NuGet Package ans save into the Nuget Package Repo/Feed | |
cd c:\nuget\source | |
Publish-Module -Path .\MyModuleName -Repository Local_Nuget_Feed -NuGetApiKey 'ABC123' | |
(The .nupkg file is created here: c:\nuget\publish) | |
-- List Packages in Repository | |
nuget list -source c:\nuget\publish | |
-- Delete Package | |
nuget delete MyModuleName 1.0.3 -source c:\nuget\publish | |
--- Install your Powershell module from the .nupkg file you just created | |
--- In an Elevated Powershell console: | |
Install-Package MyModuleName | |
-- Check Nuget Package Version After Installation | |
get-package | where-object {$_.name -match 'MyModuleName'} | |
--- Test Loading/Calling a Function from your PS Module | |
MyFunction | |
--- List all functions in your PSM1 module | |
Get-Command -Module MyModuleName | |
--- Verify the correct version of your module and manifest files were installed in the Global Modules Folder here: | |
C:\Program Files\WindowsPowerShell\Modules\MyModuleName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment