diff --git a/PSModuleDevelopment/PSModuleDevelopment.psd1 b/PSModuleDevelopment/PSModuleDevelopment.psd1 index 0c1c7e4..af8c7bb 100644 --- a/PSModuleDevelopment/PSModuleDevelopment.psd1 +++ b/PSModuleDevelopment/PSModuleDevelopment.psd1 @@ -4,7 +4,7 @@ RootModule = 'PSModuleDevelopment.psm1' # Version number of this module. - ModuleVersion = '2.2.9.106' + ModuleVersion = '2.2.9.107' # ID used to uniquely identify this module GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6' diff --git a/PSModuleDevelopment/functions/script/Publish-PSMDScriptFile.ps1 b/PSModuleDevelopment/functions/script/Publish-PSMDScriptFile.ps1 index 27582ae..636835f 100644 --- a/PSModuleDevelopment/functions/script/Publish-PSMDScriptFile.ps1 +++ b/PSModuleDevelopment/functions/script/Publish-PSMDScriptFile.ps1 @@ -1,9 +1,9 @@ function Publish-PSMDScriptFile { -<# + <# .SYNOPSIS Packages a script with all dependencies and "publishes" it as a zip package. - + .DESCRIPTION Packages a script with all dependencies and "publishes" it as a zip package. By default, it will be published to the user's desktop. @@ -12,30 +12,30 @@ - Modules that are installed in the Windows folder (such as the ActiveDirectory module or other modules associated with server roles) will be ignored. - PSSnapins will be ignored - All other modules determined by the commands used will be provided from a repository, packaged in a subfolder and included in the zip file. - + If needed, the scriptfile will be modified to add the new modules folder to its list of known folders. (The source file itself will never be modified) - + Use Set-PSMDStagingRepository to create / use a local path for staging modules to provide that way. This gives you better control over the versions used and better performance. Also the ability to use this with non-public modules. Use Publish-PSMDStagedModule to transfer modules from path or another repository into your registered staging repository. - + .PARAMETER Path Path to the scriptfile to publish. The scriptfile is expected to be UTF8 encoded with BOM, otherwise some characters may end up broken. - + .PARAMETER OutPath The path to the folder where the output zip file will be created. Defaults to the user's desktop. - + .PARAMETER EnableException This parameters disables user-friendly warnings and enables the throwing of exceptions. This is less user friendly, but allows catching exceptions in calling scripts. - + .EXAMPLE PS C:\> Publish-PSMDScriptFile -Path 'C:\scripts\logrotate.ps1' - + Creates a delivery package for the logrotate.ps1 scriptfile and places it on the desktop #> [CmdletBinding()] @@ -44,15 +44,15 @@ [PsfValidateScript('PSModuleDevelopment.Validate.File', ErrorString = 'PSModuleDevelopment.Validate.File')] [string] $Path, - + [PsfValidateScript('PSModuleDevelopment.Validate.Path', ErrorString = 'PSModuleDevelopment.Validate.Path')] [string] $OutPath = (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Script.OutPath'), - + [switch] $EnableException ) - + begin { #region Utility Functions @@ -64,10 +64,10 @@ [string] $Path ) - + $help = Get-Help $Path $modifiers = $help.alertSet.alert.Text -split "`n" | Where-Object { $_ -like "PSMD: *" } | ForEach-Object { $_ -replace '^PSMD: ' } - + foreach ($modifier in $modifiers) { $operation, $values = $modifier -split ":" @@ -106,7 +106,7 @@ } } } - + function Add-PSModulePath { [CmdletBinding()] @@ -114,7 +114,7 @@ [string] $Path ) - + $psmodulePathCode = @' # Ensure modules are available @@ -123,7 +123,7 @@ if (-not $env:PSModulePath.Contains($modulePath)) { $env:PSModulePath = "$($env: '@ - + $parsedFile = Read-PSMDScript -Path $Path $assignment = $parsedFile.Ast.FindAll({ $args[0] -is [System.Management.Automation.Language.AssignmentStatementAst] -and @@ -155,11 +155,11 @@ if (-not $env:PSModulePath.Contains($modulePath)) { $env:PSModulePath = "$($env: } } #endregion Utility Functions - + $modulesToProcess = @{ IgnoreCommand = @() - Include = @() - Exclude = @() + Include = @() + Exclude = @() } } process @@ -171,7 +171,7 @@ if (-not $env:PSModulePath.Contains($modulePath)) { $env:PSModulePath = "$($env: { $modulesToProcess.$($modifier.Type) += $modifier.Name } - + # Detect modules needed and store them try { $parsedCommands = Get-PSMDFileCommand -Path $Path -EnableException } catch @@ -183,7 +183,7 @@ if (-not $env:PSModulePath.Contains($modulePath)) { $env:PSModulePath = "$($env: { Write-PSFMessage -Level Verbose -String 'Publish-PSMDScriptFile.Script.Command' -StringValues $command.Name, $command.Count, $command.Module if ($modulesToProcess.IgnoreCommand -contains $command.Name) { continue } - + if (-not $command.Module -and -not $command.Internal) { Write-PSFMessage -Level Warning -String 'Publish-PSMDScriptFile.Script.Command.NotKnown' -StringValues $command.Name, $command.Count @@ -192,15 +192,15 @@ if (-not $env:PSModulePath.Contains($modulePath)) { $env:PSModulePath = "$($env: if ($modulesToProcess.Exclude -contains "$($command.Module)") { continue } if ($modulesToProcess.Include -contains "$($command.Module)") { continue } if ($command.Module -is [System.Management.Automation.PSSnapInInfo]) { continue } - if ($command.Module.ModuleBase -eq 'C:\Windows\System32\WindowsPowerShell\v1.0') { continue } - if ($command.Module.ModuleBase -eq 'C:\Program Files\PowerShell\7'){ continue } + if ($command.Module.ModuleBase -like 'C:\Windows\System32\WindowsPowerShell\v1.0*') { continue } + if ($command.Module.ModuleBase -like 'C:\Program Files\PowerShell\7*') { continue } $modulesToProcess.Include += "$($command.Module)" } - + $tempPath = Get-PSFPath -Name Temp $newPath = New-Item -Path $tempPath -Name "PSMD_$(Get-Random)" -ItemType Directory -Force $modulesFolder = New-Item -Path $newPath.FullName -Name 'Modules' -ItemType Directory -Force - + foreach ($moduleLabel in $modulesToProcess.Include | Select-Object -Unique) { if (-not $moduleLabel) { continue } @@ -210,13 +210,13 @@ if (-not $env:PSModulePath.Contains($modulePath)) { $env:PSModulePath = "$($env: if (Test-PSFFunctionInterrupt) { return } } #endregion Prepare required Modules - + # Copy script file $newScript = Copy-Item -Path $Path -Destination $newPath.FullName -PassThru - + # Update script to set PSModulePath Add-PSModulePath -Path $newScript.FullName - + # Zip result & move to destination Compress-Archive -Path "$($newPath.FullName)\*" -DestinationPath ('{0}\{1}.zip' -f $OutPath, $newScript.BaseName) -Force Remove-Item -Path $newPath.FullName -Recurse -Force -ErrorAction Ignore diff --git a/build/vsts-build.ps1 b/build/vsts-build.ps1 index d01d503..8c71479 100644 --- a/build/vsts-build.ps1 +++ b/build/vsts-build.ps1 @@ -30,6 +30,7 @@ if (-not $WorkingDirectory) } else { $WorkingDirectory = $env:SYSTEM_DEFAULTWORKINGDIRECTORY } } +if (-not $WorkingDirectory) { $WorkingDirectory = Split-Path $PSScriptRoot } #endregion Handle Working Directory Defaults # Prepare publish folder