Bca.NuGet
Description
Bca.NuGet is a PowerShell module used to manage NuGet packages, but more importantly helps converting known-format manifests to nuspec
(e.g. PowerShell Module Manifest, PowerShell Script Info), thus allowing you to maintain only one.
Disclaimer
-
Bca.NuGet will install the latest version of NuGet once at module import, but you can use the command
Update-NuGet
to update it. A future version will allow to specify another version or dynamically find it. - Bca.NuGet has been created to answer my needs to streamline my package automation, but I provide it to people who may need such a tool.
- It may contain bugs or lack some features, in this case, feel free to open an issue, and I'll manage it as best as I can.
- This GitHub repository is not the primary one, see transparency for more information.
- Functions that use
nuget
command (such asNew-NuGetPackage
) are natively Windows-compatible only (for now), but there is a workaround:- Install Mono 4.4.2 or later, or skip to the last step if dotnet CLI is sufficient for your needs;
- Call the function
Get-NuGetPath
, and create an alias to this command:alias nuget="mono /path/to/nuget.exe"
- Call the function
Invoke-NuGetCommand
by using theNuGetCommand
parameter with either the alias fornuget.exe
ordotnet
, for instance:Invoke-NuGetCommand -Command "restore" -NuGetCommand "nuget"
Invoke-NuGetCommand -Command "restore" -NuGetCommand "dotnet"
Invoke-NuGetCommand -Command "add" -Target "source https://api.nuget.org/v3/index.json" -Parameters @{ "name" = "NuGet.org" } -NuGetCommand "dotnet nuget"
Dependencies
-
Bca.Spdx
version0.1.1
or greater - Although it is not a dependcy, Bca.NuGet uses
Test-Xml
from modulePscx
, in the functionTest-NuspecManifest
.
Examples
Convert a PS Module Manifest
Import-PowerShellDataFile -Path .\MyModule.psd1 | ConvertTo-NuspecManifest | Save-NuspectManifest -Path "C:\MyModule.nuspec"
Convert a PS Module Object
Get-Module -Name MyModule | ConvertTo-NuspecManifest | Save-NuspectManifest -Path "C:\MyModule.nuspec"
Convert a PS Script Info
Test-ScriptFileInfo C:\MyScript.ps1 | ConvertTo-NuspecManifest | Save-NuspectManifest -Path "C:\MyScript.nuspec"
Documentation
Find extended documentation at this page.
How to install
The easiest way
In a PowerShell console, run the following:
Find-Module -Name Bca.Nuget | Install-Module
Package
Bca.NuGet is available as a package from PowerShell Gallery, NuGet and Chocolatey*, please refer to each specific plateform on how to install the package.
* Availability on Chocolatey is subject to approval.
Manually
If you decide to install Bca.NuGet manually, copy the content of src
into one or all of the path(s) contained in the variable PSModulePath
depending on the scope you need.
I'll advise you use a path with the version, that can be found in the module manifest psd1
file (e.g. C:\Program Files\WindowsPowerShell\Modules\Bca.NuGet\1.0.0
). In that case copy the content of src/Bca.NuGet
in this path.
Transparency
Please not that to date I am the only developper for this module.
- All code is primarily stored on a private Git repository on Azure DevOps;
- Issues opened in GitHub create a bug in Azure DevOps;
- All pushes made in GitHub are synced to Azure DevOps (that includes all branches except
master
); - When a GitHub Pull Request is submitted, it is analyzed and merged in
develop
on GitHub, then synced to Azure DevOps that will trigger the CI; - A Pull Request is then submitted in Azure DevOps to merge
develop
tomaster
, it runs the CI again; - Once merged to
master
, the CI is one last time, but this time it will create a Chocolatey and a NuGet packages that are pushed on private Azure DevOps Artifacts feeds; - If the CI succeeds and the packages are well pushed, the CD is triggered.
CI
The CI is an Azure DevOps build pipeline that will:
- Test the module and does code coverage with Pester;
- Run the PSScriptAnalyzer;
- Mirror the repository to GitHub
CD
The CD is an Azure DevOps release pipeline is trigerred that will:
- In a Prerelease step, install both Chocolatey and Nuget packages from the private feed in a container, and run tests again. If tests are successful, the packages are promoted to
@Prerelease
view inside the private feed; - In a Release step, publish the packages to NuGet and Chocolatey, and publish the module to PowerShell Gallery, then promote the packages to to
@Release
view inside the private feed.