/Subatomix.Build.Packaging.PowerShellModule

Package a .NET SDK-style project as a PowerShell module

Primary LanguagePerlISC LicenseISC

Subatomix.Build.Packaging.PowerShellModule

PowerShell module packaging support for .NET SDK-style projects.

Status

Build NuGet NuGet

In use by a handful of modules.

Features

  • Support for script, binary, or mixed modules
  • Module manifest templates with {VersionPrefix}, {VersionSuffix}, and {Copyright} placeholders
  • Run and debug with F5 in Visual Studio
  • Support for automated build, test, and publish

Usage

Just add a reference to this package. Now dotnet pack and Visual Studio Pack will produce a PowerShell module. Here is a minimal example .csproj file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Management.Automation"
                      Version="7.0.0" PrivateAssets="All" />
    <PackageReference Include="Subatomix.Build.Packaging.PowerShellModule"
                      Version="1.1.1" PrivateAssets="All" />
  </ItemGroup>

  <ItemGroup>
    <Content Include="$(PowerShellItemIncludes)"
             Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
  </ItemGroup>

</Project>

For a simple example, see this repository's test project. It can serve as a template for new PowerShell module projects. For a more complete, real-world example with automated tests, see my PSql module.

Ready to automate build-and-publish to PowerShell Gallery? See this repository's GitHub Actions workflow for an example.