Bca.Nuget

PowerShell module to create and manage Nuspec manifests and NuGet packages.


Keywords
Package, Packaging, PackageManager, NuGet, Windows, Linux, MacOS
License
MIT
Install
Install-Package Bca.Nuget -Version 0.0.6

Documentation

Bca.NuGet

Platform License: MIT

GitHub Release PowerShell Gallery Nuget Chocolatey

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 as New-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 the NuGetCommand parameter with either the alias for nuget.exe or dotnet, 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 version 0.1.1 or greater
  • Although it is not a dependcy, Bca.NuGet uses Test-Xml from module Pscx, in the function Test-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; Sync issue to Azure DevOps
  • All pushes made in GitHub are synced to Azure DevOps (that includes all branches except master); Sync branches to Azure DevOps
  • 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 to master, 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

Build Status

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

Build Status

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.