Skip to content

JKerens/build-powershell-modules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build.PowerShell

Description

Build PowerShell is proof of concept project to give PowerShell a first class build experience.

Business Problem

When looking at some of my favorite PowerShell modules to see how they chose to handle breaking code into consumable chunks I usually see something like this project. The problem is, how do I put it all back together when it is time to package everything? A lot of the time their answer is to create a "Merge-Files.ps1" or something of that manner.

Requirements

  • Install the newest PowerShell - Link
  • Install Dotnet Cli & SDK - Link

Building the Module

# Just use a basic dotnet build command
# Make sure you are in the same directory as the csproj file
dotnet build "Build.PowerShell.csproj"

You should end up with something like this:

BuildOutput

  • Inspecting the module
Import-Module .\artifacts\Build.PowerShell.psd1
Get-Command -Module Build.PowerShell

ImportModule

  • Using the module

InvokeDoSomething

  • .Net model class

SomethingClass

How Does it Work

The merging of the files is handled in the csproj file using the ReadLinesFromFile and WriteLinesToFile tasks. There are more detailed notes in the file itself. Private functions do not get exported due to the psd1 file targeting functions with the '*-*' pattern but private functions follow a _privateFunction naming convention.

Another neat feature is that now we can use .Net classes for our model objects. This unlocks a lot more features like interfaces and namespaces that PowerShell classes don't have.


About

Using dotnet cli to build your PowerShell module

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published