psake / PowerShellBuild

Common build tasks for psake and Invoke-Build that build and test PowerShell modules
MIT License
134 stars 24 forks source link

Build.Exclude ignored when Build.CompileModule is $true #40

Closed pauby closed 4 years ago

pauby commented 4 years ago

When $PSBPreference.Build.CompileModule is $true the $PSBPreference.Build.Exclude is ignored and all .ps1 files found are used in the PSM1 file.

Expected Behavior

The files to be excluded in the $PSBPreference.Build.Exclude is honoured and the files are excluded from being compiled into the PSM1 file.

Current Behavior

When $PSBPreference.Build.CompileModule is $true the $PSBPreference.Build.Exclude is ignored and all .ps1 files found are used in the PSM1 file.

Possible Solution

The files are excluded.

Steps to Reproduce (for bugs)

Note you need to setup a proper build for this. These steps are those things that must be set / done:

  1. Set $PSBPreference.Build.Exclude to a file to be excluded;
  2. Set $PSBPreference.Build.CompileModule to $true
  3. Run the build;

Context

I am trying to exclude a folder of files from being compiled into the PSM1 file.

Your Environment

pauby commented 4 years ago

I've created a PR for this to demonstrate the code. Unfortunately the -Exclude parameter in Get-ChildItem has been broken for a while (I tried it again for this PR just in case anything has changed from the last time I pulled my hair out over it and it hasn't) so I had to resort to the Where clause. However it does allow the user to specify regular expression(s) to match the files whcih I think is better. However this does require two ways of working:

  1. If $PSBPreference.Build.CompileModuleis$truethen$PSBPreference.Build.Exclude` should be regular expressions;
  2. If $PSBPreference.Build.CompileModule is $false then $PSBPreference.Build.Exclude should just be an array of file names (as these are passed to Copy-Item further down the code).

I would rather we stuck with one or the other so would welcome a discussion on that.