From 12b8f75283a195d64b1b9c521aa61bec88ab493f Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Thu, 6 Oct 2016 23:58:52 -0600 Subject: [PATCH 1/2] Refactored psake build script. This separates out the user customizations into a separate file build.settings.ps1. Also made changes related to the discussion in issue #145. Fixed some bugs with the build script as well after a fair bit of testing. Too bad my code-signing cert expired last month. Hopefully DigiCert will come through with a new cert so I can test the Sign task. --- .vscode/tasks.json | 6 +- build.ps1 | 8 +- build.psake.ps1 | 236 ++++++------------ build.settings.ps1 | 133 ++++++++++ src/Templates/NewModule/build.ps1 | 8 +- src/Templates/NewModule/build.psake.ps1 | 236 ++++++------------ src/Templates/NewModule/build.settings.ps1 | 133 ++++++++++ .../NewModule/editor/VSCode/tasks.json | 9 + src/Templates/NewModule/plasterManifest.xml | 4 +- 9 files changed, 430 insertions(+), 343 deletions(-) create mode 100644 build.settings.ps1 create mode 100644 src/Templates/NewModule/build.settings.ps1 diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 5388268..d598f23 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -66,12 +66,12 @@ ] }, { - "taskName": "Build Docs", + "taskName": "BuildHelp", "suppressTaskName": true, "showOutput": "always", "args": [ - "Write-Host 'Invoking psake...'; Invoke-psake build.psake.ps1 -taskList BuildDocs;", - "Invoke-Command { Write-Host 'Completed BuildDocs task in task runner.' }" + "Write-Host 'Invoking psake...'; Invoke-psake build.psake.ps1 -taskList BuildHelp;", + "Invoke-Command { Write-Host 'Completed BuildHelp task in task runner.' }" ] }, { diff --git a/build.ps1 b/build.ps1 index 873fa1f..632433c 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,8 +1,4 @@ -# This builds this module by invoking the build.psake.ps1 script +#Requires -Modules psake -if ($null -eq (Get-Module -Name PSake -ListAvailable)) { - throw "You need to install PSake before continuing. Install with 'Install-Module PSake -Scope CurrentUser'." -} - -Import-Module Psake +# Builds the module by invoking psake on the build.psake.ps1 script. Invoke-PSake $PSScriptRoot\build.psake.ps1 -taskList Build diff --git a/build.psake.ps1 b/build.psake.ps1 index 909c3bf..3813d0e 100644 --- a/build.psake.ps1 +++ b/build.psake.ps1 @@ -1,179 +1,87 @@ +#Requires -Modules psake + +############################################################################## +# DO NOT MODIFY THIS FILE! Modify build.settings.ps1 instead. +############################################################################## + ############################################################################## -# Requirements: psake. If you don't have this module installed use the following -# command to install it: +# This is the PowerShell Module psake build script. It defines the following tasks: # -# PS C:\> Install-Module psake -Scope CurrentUser +# Clean, Build, Sign, BuildHelp, Install, Test and Publish. # -############################################################################## -# This is a psake script that supports the following tasks: -# clean, build, sign, docgen, install, test and publish. -# The default task is build. +# The default task is Build. This task copies the appropriate files from the +# $SrcRootDir to the $OutDir. Later, other tasks such as Sign and BuildHelp +# will further modify the contents of $OutDir and add new files. # -# The publish task uses the Publish-Module command to publish -# to either the PowerShell Gallery (the default) or you can change -# the $Repository property to the name of an alternate repository. +# The Sign task will only sign scripts if the $SignScripts variable is set to +# $true. A code-signing certificate is required for this task to complete. # -# The test task invokes Pester to run any Pester tests in your -# workspace folder. Name your test scripts .Tests.ps1 -# and Pester will find and run the tests contained in the files. +# The BuildHelp task invokes platyPS to generate markdown files from +# comment-based help for your exported commands. platyPS then generates +# a help file for your module from the markdown files. # -# You can run this build script directly using the invoke-psake -# command which will execute the build task. This task "builds" -# a temporary folder from which the module can be published. +# The Install task simplies copies the $OutDir to your profile's Modules folder. # -# PS C:\> invoke-psake build.psake.ps1 +# The Test task invokes Pester on the $TestRootDir. +# +# The Publish task uses the Publish-Module command to publish +# to either the PowerShell Gallery (the default) or you can change +# the $PublishRepository property to the name of an alternate repository. +# Note: the Publish task requires that the Test task execute without failures. # -# You can run your Pester tests (if any) by running the following command. +# You can exeute a specific task, such as the Test task by running the +# following command: # -# PS C:\> invoke-psake build.psake.ps1 -taskList test +# PS C:\> invoke-psake build.psake.ps1 -taskList Test # -# You can execute the publish task with the following command. Note that -# the publish task will run the test task first. The Pester tests must pass -# before the publish task will run. The first time you run the publish -# command, you will be prompted to enter your PowerShell Gallery NuGetApiKey. -# After entering the key, it is encrypted and stored so you will not have to -# enter it again. +# You can execute the Publish task with the following command. +# The first time you execute the Publish task, you will be prompted to enter +# your PowerShell Gallery NuGetApiKey. After entering the key, it is encrypted +# and stored so you will not have to enter it again. # -# PS C:\> invoke-psake build.psake.ps1 -taskList publish +# PS C:\> invoke-psake build.psake.ps1 -taskList Publish # # You can verify the stored and encrypted NuGetApiKey by running the following -# command. This will display your NuGetApiKey in plain text! +# command which will display a portion of your NuGetApiKey in plain text. # -# PS C:\> invoke-psake build.psake.ps1 -taskList showApiKey +# PS C:\> invoke-psake build.psake.ps1 -taskList ShowApiKey # # You can store a new NuGetApiKey with this command. You can leave off # the -properties parameter and you'll be prompted for the key. # -# PS C:\> invoke-psake build.psake.ps1 -taskList storeApiKey -properties @{NuGetApiKey='test123'} +# PS C:\> invoke-psake build.psake.ps1 -taskList StoreApiKey -properties @{NuGetApiKey='test123'} # ############################################################################### -# Customize these properties for your module. +# Dot source the user's customized properties and extension tasks. ############################################################################### - -Properties { - # ----------------------- Basic properties -------------------------------- - - # The root directory of the module source and tests. It could be the workspace - # root or a subdir such as src, module, . - $SourceRootDir = "$PSScriptRoot/src" - $TestRootDir = "$PSScriptRoot/test" - $DocsRootDir = "$PSScriptRoot/docs" - - # Default Locale used for documentation generatioon, defaults to en-US. - $DefaultLocale = $null - - # -------------------- Publishing properties ------------------------------ - - # Path to the release notes file. Set to $null if the release notes reside in the manifest file. - # The contents of this file are used during publishing for the ReleaseNotes parameter. - $ReleaseNotesPath = "$PSScriptRoot/ReleaseNotes.md" - - # Set to $true if you want to sign your scripts. You will need to have a code-signing certificate. - # You can specify the certificate's subject name below. If not specified, you will be prompted to - # provide either a subject name or path to a PFX file. After this one time prompt, the value will - # saved for future use and you will no longer be prompted. - $SignScripts = $false - - # Specify the Subject Name of the certificate used to sign your scripts. Leave it as $null and the - # first time you build, you will be prompted to enter your API key. This variable is used only if - # $SignScripts is set to $true. This does require the code-signing certificate to be installed - # to your certificate store. If you have a code-signing certificate in a PFX file, install the - # certificate to your certificate store with the command below. You may be prompted for the - # certificate's password. - # - # Import-PfxCertificate -FilePath .\myCodeSigingCert.pfx -CertStoreLocation Cert:\CurrentUser\My - $CertSubjectName = $null - - # Your NuGet API key for the PSGallery. Leave it as $null and the first time - # you publish, you will be prompted to enter your API key. The build will - # store the key encrypted in the settings file, so that on subsequent - # publishes you will no longer be prompted for the API key. - $NuGetApiKey = $null - - # Name of the repository you wish to publish to. Default repo is the PowerShellGallery. - $PublishRepository = $null - - # ----------------------- Misc properties --------------------------------- - - # In addition, PFX certificates are supported in an interactive scenario only, - # as a way to import a certificate into the user personal store for later use. - # This can be provided using the CertPfxPath parameter. PFX passwords will not be stored. - $SettingsPath = "$env:LOCALAPPDATA\Plaster\NewModuleTemplate\SecuredBuildSettings.clixml" - - # The name of your module should match the basename of the PSD1 file. - $ModuleName = (Get-Item $SourceRootDir/*.psd1 | - Foreach-Object {$null = Test-ModuleManifest -Path $_ -ErrorAction SilentlyContinue; if ($?) { $_ }})[0].BaseName - - # The module summary from the PSD1 file. - $ModuleDetails = Test-ModuleManifest -Path "$SourceRootDir\$ModuleName.psd1" - - # The directory used to publish the module from. If you are using Git, the - # $PublishRootDir should be ignored if it is under the workspace directory. - $PublishRootDir = "$PSScriptRoot\Release" - $PublishDir = "$PublishRootDir\$ModuleName" - - # The local installation directory for the install task. Defaults to your user PSModulePath. - $InstallPath = $null - - # The following items will not be copied to the $PublishDir. Typically you - # wouldn't put any file under the src dir unless the file was going to ship with - # the module. However, if there are such files, add them to the exclude list below. - $Exclude = @() - - # Specifies an output file path to send to Invoke-Pester's -OutputFile parameter. - # This is typically used to write out test results so that they can be sent to a CI - # system like AppVeyor. - $TestOutputFile = $null - - # Specifies the test output format to use when the TestOutputFile property is given - # a path. This parameter is passed through to Invoke-Pester's -OutputFormat parameter. - $TestOutputFormat = "NUnitXml" -} - -############################################################################### -# Customize these tasks for performing operations before and/or after publish. -############################################################################### - -# Executes before src is copied to publish dir -Task PreCopySource { -} - -# Executes after src is copied to publish dir -Task PostCopySource { -} - -# Executes before publishing occurs. -Task PrePublish { -} - -# Executes after publishing occurs. -Task PostPublish { -} - +. $PSScriptRoot\build.settings.ps1 ############################################################################### -# Core task implementations +# Core task implementations. Avoid modifying these tasks. ############################################################################### Task default -depends Build -Task Init -requiredVariables PublishDir { - if (!(Test-Path $PublishDir) -and $PublishDir.StartsWith($PSScriptRoot, 'OrdinalIgnoreCase')) { - New-Item $PublishDir -ItemType Directory > $null +Task Init -requiredVariables OutDir { + if (!(Test-Path $OutDir) -and $OutDir.StartsWith($PSScriptRoot, 'OrdinalIgnoreCase')) { + New-Item $OutDir -ItemType Directory > $null } } -Task Clean -requiredVariables PublishRootDir { - if ((Test-Path $PublishRootDir) -and $PublishRootDir.StartsWith($PSScriptRoot, 'OrdinalIgnoreCase')) { - Get-ChildItem $PublishRootDir | Remove-Item -Recurse -Force -Verbose:$VerbosePreference +Task Clean -requiredVariables ReleaseDir { + if ((Test-Path $ReleaseDir) -and $ReleaseDir.StartsWith($PSScriptRoot, 'OrdinalIgnoreCase')) { + Get-ChildItem $ReleaseDir | Remove-Item -Recurse -Force -Verbose:$VerbosePreference } } -Task CopySource -depends Init, Clean -requiredVariables SourceRootDir, PublishDir { - Copy-Item -Path $SourceRootDir -Destination $PublishDir -Recurse -Exclude $Exclude -Verbose:$VerbosePreference +Task Build -depends BuildImpl, Sign, PostBuild { +} + +Task BuildImpl -depends Init, Clean, PreBuild -requiredVariables SrcRootDir, OutDir { + Copy-Item -Path $SrcRootDir -Destination $OutDir -Recurse -Exclude $Exclude -Verbose:$VerbosePreference } -Task Sign -depends CopySource -requiredVariables SettingsPath, SignScripts { +Task Sign -depends BuildImpl -requiredVariables SettingsPath, SignScripts { if (!$SignScripts) { "Script signing is not enabled. Skipping Sign task." return @@ -196,7 +104,7 @@ Task Sign -depends CopySource -requiredVariables SettingsPath, SignScripts { # Find a code-signing certificate that matches the specified subject name. $cert = Get-ChildItem -Path Cert:\ -CodeSigningCert -Recurse | - Where-Object { $_.SubjectName.Name.StartsWith($CertSubjectName) -and $_.NotAfter -gt (Get-Date) } | + Where-Object { $_.SubjectName.Name.StartsWith($CertSubjectName) -and ($_.NotAfter -ge (Get-Date)) } | Sort-Object -Property NotAfter -Descending | Select-Object -First 1 if ($cert) { @@ -209,9 +117,9 @@ Task Sign -depends CopySource -requiredVariables SettingsPath, SignScripts { } $certificate = Get-ChildItem Cert:\CurrentUser\My | Where-Object { $_.Thumbprint -eq $cert.Thumbprint } - "Using certificate $certificate to sign scripts." + "Using code-signing certificate: $certificate" - $files = @(Get-ChildItem -Path $PublishDir\* -Recurse -Include '*.ps1', '*.psm1') + $files = @(Get-ChildItem -Path $OutDir\* -Recurse -Include *.ps1,*.psm1) foreach ($file in $files) { $result = Set-AuthenticodeSignature -FilePath $file.FullName -Certificate $certificate -Verbose:$VerbosePreference if ($result.Status -ne 'Valid') { @@ -226,15 +134,12 @@ Task Sign -depends CopySource -requiredVariables SettingsPath, SignScripts { } } -Task Build -depends PreCopySource, CopySource, PostCopySource, Sign { -} - -Task GenerateDocs -depends Build { +Task GenerateMarkdown -depends Build, PreBuildHelp -requiredVariables DocsRootDir, ModuleName, OutDir { if ($null -eq $DefaultLocale) { $DefaultLocale = 'en-US' } - $moduleInfo = Import-Module $PublishDir\$ModuleName.psd1 -Global -Force -PassThru + $moduleInfo = Import-Module $OutDir\$ModuleName.psd1 -Global -Force -PassThru if ($moduleInfo.ExportedCommands.Count -eq 0) { "No commands have been exported. Skipping GenerateDocs task." return @@ -256,22 +161,29 @@ Task GenerateDocs -depends Build { Remove-Module $ModuleName } -Task BuildDocs -depends GenerateDocs { +Task BuildHelp -depends BuildHelpImpl, PostBuildHelp { +} + +Task BuildHelpImpl -depends GenerateMarkdown -requiredVariables DocsRootDir, OutDir { if (!(Test-Path -LiteralPath $DocsRootDir) -or !(Get-ChildItem -LiteralPath $DocsRootDir -Filter *.md -Recurse)) { "No markdown help files to process. Skipping BuildDocs task." return } foreach ($locale in (Get-ChildItem -Path $DocsRootDir -Directory).Name) { - New-ExternalHelp -Path $DocsRootDir\$locale -OutputPath $PublishDir\$locale -Force -ErrorAction SilentlyContinue | Out-Null + New-ExternalHelp -Path $DocsRootDir\$locale -OutputPath $OutDir\$locale -Force -ErrorAction SilentlyContinue | Out-Null } } -Task Install -depends BuildDocs { +Task Install -depends InstallImpl, PostInstall { +} + +Task InstallImpl -depends BuildHelp, PreInstall -requiredVariables OutDir { if ($null -eq $InstallPath) { - # The default installation path is the user's PSModulePath + # The default installation path is the current user's module path. + $moduleInfo = Test-ModuleManifest -Path $SrcRootDir\$ModuleName.psd1 $InstallPath = Join-Path -Path (Split-Path $profile.CurrentUserAllHosts -Parent) ` - -ChildPath "Modules\$ModuleName\$($ModuleDetails.Version.ToString())" + -ChildPath "Modules\$ModuleName\$($moduleInfo.Version.ToString())" } if (!(Test-Path -Path $InstallPath)) { @@ -279,16 +191,16 @@ Task Install -depends BuildDocs { New-Item -Path $InstallPath -ItemType Directory -Verbose:$VerbosePreference > $null } - Copy-Item -Path $PublishDir\* -Destination $InstallPath -Verbose:$VerbosePreference -Recurse -Force + Copy-Item -Path $OutDir\* -Destination $InstallPath -Verbose:$VerbosePreference -Recurse -Force } -Task Test -depends Build { +Task Test -depends Build -requiredVariables TestRootDir, ModuleName { Import-Module Pester try { Microsoft.PowerShell.Management\Push-Location -LiteralPath $TestRootDir - if ($TestOutputFile -ne $null) { + if ($TestOutputFile) { $TestResult = Invoke-Pester -OutputFile $TestOutputFile -OutputFormat $TestOutputFormat -PassThru -Verbose:$VerbosePreference } else { @@ -299,16 +211,16 @@ Task Test -depends Build { } finally { Microsoft.PowerShell.Management\Pop-Location - Remove-Module $ModuleName + Remove-Module $ModuleName -ErrorAction SilentlyContinue } } Task Publish -depends Test, PrePublish, PublishImpl, PostPublish { } -Task PublishImpl -depends Test -requiredVariables SettingsPath, PublishDir { +Task PublishImpl -requiredVariables SettingsPath, OutDir { $publishParams = @{ - Path = $PublishDir + Path = $OutDir NuGetApiKey = $NuGetApiKey } @@ -332,7 +244,7 @@ Task PublishImpl -depends Test -requiredVariables SettingsPath, PublishDir { } $publishParams = @{ - Path = $PublishDir + Path = $OutDir NuGetApiKey = $NuGetApiKey } @@ -350,7 +262,6 @@ Task PublishImpl -depends Test -requiredVariables SettingsPath, PublishDir { Publish-Module @publishParams } - ############################################################################### # Secondary/utility tasks - typically used to manage stored build settings. ############################################################################### @@ -434,7 +345,6 @@ Task ShowCertSubjectName -requiredVariables SettingsPath { } } - ############################################################################### # Helper functions ############################################################################### diff --git a/build.settings.ps1 b/build.settings.ps1 new file mode 100644 index 0000000..a7f2aac --- /dev/null +++ b/build.settings.ps1 @@ -0,0 +1,133 @@ +############################################################################### +# Customize these properties and tasks for your module. +############################################################################### + +Properties { + # ----------------------- Basic properties -------------------------------- + + # The root directories for the module's docs, src and test. + $DocsRootDir = "$PSScriptRoot/docs" + $SrcRootDir = "$PSScriptRoot/src" + $TestRootDir = "$PSScriptRoot/test" + + # The name of your module should match the basename of the PSD1 file. + $ModuleName = Get-Item $SrcRootDir/*.psd1 | + Where-Object { $null -ne (Test-ModuleManifest -Path $_ -ErrorAction SilentlyContinue) } | + Select-Object -First 1 | Foreach-Object BaseName + + # The $OutDir must match the ModuleName in order to support publishing the module. + $ReleaseDir = "$PSScriptRoot/Release" + $OutDir = "$ReleaseDir/$ModuleName" + + # Default Locale used for documentation generatioon, defaults to en-US. + $DefaultLocale = $null + + # Items in the $Exclude array will not be copied to the $OutDir e.g. $Exclude = @('.gitattributes') + # Typically you wouldn't put any file under the src dir unless the file was going to ship with + # the module. However, if there are such files, add their $SrcRootDir relative paths to the exclude list. + $Exclude = @() + + + # ------------------- Script signing properties --------------------------- + + # Set to $true if you want to sign your scripts. You will need to have a code-signing certificate. + # You can specify the certificate's subject name below. If not specified, you will be prompted to + # provide either a subject name or path to a PFX file. After this one time prompt, the value will + # saved for future use and you will no longer be prompted. + $SignScripts = $false + + # Specify the Subject Name of the certificate used to sign your scripts. Leave it as $null and the + # first time you build, you will be prompted to enter your code-signing certificate's Subject Name. + # This variable is used only if $SignScripts is set to $true. + # + # This does require the code-signing certificate to be installed to your certificate store. If you + # have a code-signing certificate in a PFX file, install the certificate to your certificate store + # with the command below. You may be prompted for the certificate's password. + # + # Import-PfxCertificate -FilePath .\myCodeSigingCert.pfx -CertStoreLocation Cert:\CurrentUser\My + # + $CertSubjectName = $null + + + # -------------------- Publishing properties ------------------------------ + + # Your NuGet API key for the PSGallery. Leave it as $null and the first time you publish, + # you will be prompted to enter your API key. The build will store the key encrypted in the + # settings file, so that on subsequent publishes you will no longer be prompted for the API key. + $NuGetApiKey = $null + + # Name of the repository you wish to publish to. If $null is specified the default repo (PowerShellGallery) is used. + $PublishRepository = $null + + # Path to the release notes file. Set to $null if the release notes reside in the manifest file. + # The contents of this file are used during publishing for the ReleaseNotes parameter. + $ReleaseNotesPath = "$PSScriptRoot/ReleaseNotes.md" + + + # ----------------------- Misc properties --------------------------------- + + # In addition, PFX certificates are supported in an interactive scenario only, + # as a way to import a certificate into the user personal store for later use. + # This can be provided using the CertPfxPath parameter. PFX passwords will not be stored. + $SettingsPath = "$env:LOCALAPPDATA\Plaster\NewModuleTemplate\SecuredBuildSettings.clixml" + + # The local installation directory for the install task. Defaults to your user PSModulePath. + $InstallPath = $null + + # Specifies an output file path to send to Invoke-Pester's -OutputFile parameter. + # This is typically used to write out test results so that they can be sent to a CI + # system like AppVeyor. + $TestOutputFile = $null + + # Specifies the test output format to use when the TestOutputFile property is given + # a path. This parameter is passed through to Invoke-Pester's -OutputFormat parameter. + $TestOutputFormat = "NUnitXml" +} + +############################################################################### +# Customize these tasks for performing operations before and/or after Build. +############################################################################### + +# Executes before the BuildImpl phase of the Build task. +Task PreBuild { +} + +# Executes after the Sign phase of the Build task. +Task PostBuild { +} + +############################################################################### +# Customize these tasks for performing operations before and/or after BuildHelp. +############################################################################### + +# Executes before the GenerateMarkdown phase of the BuildHelp task. +Task PreBuildHelp { +} + +# Executes after the BuildHelpImpl phase of the BuildHelp task. +Task PostBuildHelp { +} + +############################################################################### +# Customize these tasks for performing operations before and/or after Install. +############################################################################### + +# Executes before the InstallImpl phase of the Install task. +Task PreInstall { +} + +# Executes after the InstallImpl phase of the Install task. +Task PostInstall { +} + +############################################################################### +# Customize these tasks for performing operations before and/or after Publish. +############################################################################### + +# Executes before publishing occurs. +Task PrePublish { +} + +# Executes after publishing occurs. +Task PostPublish { +} diff --git a/src/Templates/NewModule/build.ps1 b/src/Templates/NewModule/build.ps1 index 873fa1f..632433c 100644 --- a/src/Templates/NewModule/build.ps1 +++ b/src/Templates/NewModule/build.ps1 @@ -1,8 +1,4 @@ -# This builds this module by invoking the build.psake.ps1 script +#Requires -Modules psake -if ($null -eq (Get-Module -Name PSake -ListAvailable)) { - throw "You need to install PSake before continuing. Install with 'Install-Module PSake -Scope CurrentUser'." -} - -Import-Module Psake +# Builds the module by invoking psake on the build.psake.ps1 script. Invoke-PSake $PSScriptRoot\build.psake.ps1 -taskList Build diff --git a/src/Templates/NewModule/build.psake.ps1 b/src/Templates/NewModule/build.psake.ps1 index 909c3bf..3813d0e 100644 --- a/src/Templates/NewModule/build.psake.ps1 +++ b/src/Templates/NewModule/build.psake.ps1 @@ -1,179 +1,87 @@ +#Requires -Modules psake + +############################################################################## +# DO NOT MODIFY THIS FILE! Modify build.settings.ps1 instead. +############################################################################## + ############################################################################## -# Requirements: psake. If you don't have this module installed use the following -# command to install it: +# This is the PowerShell Module psake build script. It defines the following tasks: # -# PS C:\> Install-Module psake -Scope CurrentUser +# Clean, Build, Sign, BuildHelp, Install, Test and Publish. # -############################################################################## -# This is a psake script that supports the following tasks: -# clean, build, sign, docgen, install, test and publish. -# The default task is build. +# The default task is Build. This task copies the appropriate files from the +# $SrcRootDir to the $OutDir. Later, other tasks such as Sign and BuildHelp +# will further modify the contents of $OutDir and add new files. # -# The publish task uses the Publish-Module command to publish -# to either the PowerShell Gallery (the default) or you can change -# the $Repository property to the name of an alternate repository. +# The Sign task will only sign scripts if the $SignScripts variable is set to +# $true. A code-signing certificate is required for this task to complete. # -# The test task invokes Pester to run any Pester tests in your -# workspace folder. Name your test scripts .Tests.ps1 -# and Pester will find and run the tests contained in the files. +# The BuildHelp task invokes platyPS to generate markdown files from +# comment-based help for your exported commands. platyPS then generates +# a help file for your module from the markdown files. # -# You can run this build script directly using the invoke-psake -# command which will execute the build task. This task "builds" -# a temporary folder from which the module can be published. +# The Install task simplies copies the $OutDir to your profile's Modules folder. # -# PS C:\> invoke-psake build.psake.ps1 +# The Test task invokes Pester on the $TestRootDir. +# +# The Publish task uses the Publish-Module command to publish +# to either the PowerShell Gallery (the default) or you can change +# the $PublishRepository property to the name of an alternate repository. +# Note: the Publish task requires that the Test task execute without failures. # -# You can run your Pester tests (if any) by running the following command. +# You can exeute a specific task, such as the Test task by running the +# following command: # -# PS C:\> invoke-psake build.psake.ps1 -taskList test +# PS C:\> invoke-psake build.psake.ps1 -taskList Test # -# You can execute the publish task with the following command. Note that -# the publish task will run the test task first. The Pester tests must pass -# before the publish task will run. The first time you run the publish -# command, you will be prompted to enter your PowerShell Gallery NuGetApiKey. -# After entering the key, it is encrypted and stored so you will not have to -# enter it again. +# You can execute the Publish task with the following command. +# The first time you execute the Publish task, you will be prompted to enter +# your PowerShell Gallery NuGetApiKey. After entering the key, it is encrypted +# and stored so you will not have to enter it again. # -# PS C:\> invoke-psake build.psake.ps1 -taskList publish +# PS C:\> invoke-psake build.psake.ps1 -taskList Publish # # You can verify the stored and encrypted NuGetApiKey by running the following -# command. This will display your NuGetApiKey in plain text! +# command which will display a portion of your NuGetApiKey in plain text. # -# PS C:\> invoke-psake build.psake.ps1 -taskList showApiKey +# PS C:\> invoke-psake build.psake.ps1 -taskList ShowApiKey # # You can store a new NuGetApiKey with this command. You can leave off # the -properties parameter and you'll be prompted for the key. # -# PS C:\> invoke-psake build.psake.ps1 -taskList storeApiKey -properties @{NuGetApiKey='test123'} +# PS C:\> invoke-psake build.psake.ps1 -taskList StoreApiKey -properties @{NuGetApiKey='test123'} # ############################################################################### -# Customize these properties for your module. +# Dot source the user's customized properties and extension tasks. ############################################################################### - -Properties { - # ----------------------- Basic properties -------------------------------- - - # The root directory of the module source and tests. It could be the workspace - # root or a subdir such as src, module, . - $SourceRootDir = "$PSScriptRoot/src" - $TestRootDir = "$PSScriptRoot/test" - $DocsRootDir = "$PSScriptRoot/docs" - - # Default Locale used for documentation generatioon, defaults to en-US. - $DefaultLocale = $null - - # -------------------- Publishing properties ------------------------------ - - # Path to the release notes file. Set to $null if the release notes reside in the manifest file. - # The contents of this file are used during publishing for the ReleaseNotes parameter. - $ReleaseNotesPath = "$PSScriptRoot/ReleaseNotes.md" - - # Set to $true if you want to sign your scripts. You will need to have a code-signing certificate. - # You can specify the certificate's subject name below. If not specified, you will be prompted to - # provide either a subject name or path to a PFX file. After this one time prompt, the value will - # saved for future use and you will no longer be prompted. - $SignScripts = $false - - # Specify the Subject Name of the certificate used to sign your scripts. Leave it as $null and the - # first time you build, you will be prompted to enter your API key. This variable is used only if - # $SignScripts is set to $true. This does require the code-signing certificate to be installed - # to your certificate store. If you have a code-signing certificate in a PFX file, install the - # certificate to your certificate store with the command below. You may be prompted for the - # certificate's password. - # - # Import-PfxCertificate -FilePath .\myCodeSigingCert.pfx -CertStoreLocation Cert:\CurrentUser\My - $CertSubjectName = $null - - # Your NuGet API key for the PSGallery. Leave it as $null and the first time - # you publish, you will be prompted to enter your API key. The build will - # store the key encrypted in the settings file, so that on subsequent - # publishes you will no longer be prompted for the API key. - $NuGetApiKey = $null - - # Name of the repository you wish to publish to. Default repo is the PowerShellGallery. - $PublishRepository = $null - - # ----------------------- Misc properties --------------------------------- - - # In addition, PFX certificates are supported in an interactive scenario only, - # as a way to import a certificate into the user personal store for later use. - # This can be provided using the CertPfxPath parameter. PFX passwords will not be stored. - $SettingsPath = "$env:LOCALAPPDATA\Plaster\NewModuleTemplate\SecuredBuildSettings.clixml" - - # The name of your module should match the basename of the PSD1 file. - $ModuleName = (Get-Item $SourceRootDir/*.psd1 | - Foreach-Object {$null = Test-ModuleManifest -Path $_ -ErrorAction SilentlyContinue; if ($?) { $_ }})[0].BaseName - - # The module summary from the PSD1 file. - $ModuleDetails = Test-ModuleManifest -Path "$SourceRootDir\$ModuleName.psd1" - - # The directory used to publish the module from. If you are using Git, the - # $PublishRootDir should be ignored if it is under the workspace directory. - $PublishRootDir = "$PSScriptRoot\Release" - $PublishDir = "$PublishRootDir\$ModuleName" - - # The local installation directory for the install task. Defaults to your user PSModulePath. - $InstallPath = $null - - # The following items will not be copied to the $PublishDir. Typically you - # wouldn't put any file under the src dir unless the file was going to ship with - # the module. However, if there are such files, add them to the exclude list below. - $Exclude = @() - - # Specifies an output file path to send to Invoke-Pester's -OutputFile parameter. - # This is typically used to write out test results so that they can be sent to a CI - # system like AppVeyor. - $TestOutputFile = $null - - # Specifies the test output format to use when the TestOutputFile property is given - # a path. This parameter is passed through to Invoke-Pester's -OutputFormat parameter. - $TestOutputFormat = "NUnitXml" -} - -############################################################################### -# Customize these tasks for performing operations before and/or after publish. -############################################################################### - -# Executes before src is copied to publish dir -Task PreCopySource { -} - -# Executes after src is copied to publish dir -Task PostCopySource { -} - -# Executes before publishing occurs. -Task PrePublish { -} - -# Executes after publishing occurs. -Task PostPublish { -} - +. $PSScriptRoot\build.settings.ps1 ############################################################################### -# Core task implementations +# Core task implementations. Avoid modifying these tasks. ############################################################################### Task default -depends Build -Task Init -requiredVariables PublishDir { - if (!(Test-Path $PublishDir) -and $PublishDir.StartsWith($PSScriptRoot, 'OrdinalIgnoreCase')) { - New-Item $PublishDir -ItemType Directory > $null +Task Init -requiredVariables OutDir { + if (!(Test-Path $OutDir) -and $OutDir.StartsWith($PSScriptRoot, 'OrdinalIgnoreCase')) { + New-Item $OutDir -ItemType Directory > $null } } -Task Clean -requiredVariables PublishRootDir { - if ((Test-Path $PublishRootDir) -and $PublishRootDir.StartsWith($PSScriptRoot, 'OrdinalIgnoreCase')) { - Get-ChildItem $PublishRootDir | Remove-Item -Recurse -Force -Verbose:$VerbosePreference +Task Clean -requiredVariables ReleaseDir { + if ((Test-Path $ReleaseDir) -and $ReleaseDir.StartsWith($PSScriptRoot, 'OrdinalIgnoreCase')) { + Get-ChildItem $ReleaseDir | Remove-Item -Recurse -Force -Verbose:$VerbosePreference } } -Task CopySource -depends Init, Clean -requiredVariables SourceRootDir, PublishDir { - Copy-Item -Path $SourceRootDir -Destination $PublishDir -Recurse -Exclude $Exclude -Verbose:$VerbosePreference +Task Build -depends BuildImpl, Sign, PostBuild { +} + +Task BuildImpl -depends Init, Clean, PreBuild -requiredVariables SrcRootDir, OutDir { + Copy-Item -Path $SrcRootDir -Destination $OutDir -Recurse -Exclude $Exclude -Verbose:$VerbosePreference } -Task Sign -depends CopySource -requiredVariables SettingsPath, SignScripts { +Task Sign -depends BuildImpl -requiredVariables SettingsPath, SignScripts { if (!$SignScripts) { "Script signing is not enabled. Skipping Sign task." return @@ -196,7 +104,7 @@ Task Sign -depends CopySource -requiredVariables SettingsPath, SignScripts { # Find a code-signing certificate that matches the specified subject name. $cert = Get-ChildItem -Path Cert:\ -CodeSigningCert -Recurse | - Where-Object { $_.SubjectName.Name.StartsWith($CertSubjectName) -and $_.NotAfter -gt (Get-Date) } | + Where-Object { $_.SubjectName.Name.StartsWith($CertSubjectName) -and ($_.NotAfter -ge (Get-Date)) } | Sort-Object -Property NotAfter -Descending | Select-Object -First 1 if ($cert) { @@ -209,9 +117,9 @@ Task Sign -depends CopySource -requiredVariables SettingsPath, SignScripts { } $certificate = Get-ChildItem Cert:\CurrentUser\My | Where-Object { $_.Thumbprint -eq $cert.Thumbprint } - "Using certificate $certificate to sign scripts." + "Using code-signing certificate: $certificate" - $files = @(Get-ChildItem -Path $PublishDir\* -Recurse -Include '*.ps1', '*.psm1') + $files = @(Get-ChildItem -Path $OutDir\* -Recurse -Include *.ps1,*.psm1) foreach ($file in $files) { $result = Set-AuthenticodeSignature -FilePath $file.FullName -Certificate $certificate -Verbose:$VerbosePreference if ($result.Status -ne 'Valid') { @@ -226,15 +134,12 @@ Task Sign -depends CopySource -requiredVariables SettingsPath, SignScripts { } } -Task Build -depends PreCopySource, CopySource, PostCopySource, Sign { -} - -Task GenerateDocs -depends Build { +Task GenerateMarkdown -depends Build, PreBuildHelp -requiredVariables DocsRootDir, ModuleName, OutDir { if ($null -eq $DefaultLocale) { $DefaultLocale = 'en-US' } - $moduleInfo = Import-Module $PublishDir\$ModuleName.psd1 -Global -Force -PassThru + $moduleInfo = Import-Module $OutDir\$ModuleName.psd1 -Global -Force -PassThru if ($moduleInfo.ExportedCommands.Count -eq 0) { "No commands have been exported. Skipping GenerateDocs task." return @@ -256,22 +161,29 @@ Task GenerateDocs -depends Build { Remove-Module $ModuleName } -Task BuildDocs -depends GenerateDocs { +Task BuildHelp -depends BuildHelpImpl, PostBuildHelp { +} + +Task BuildHelpImpl -depends GenerateMarkdown -requiredVariables DocsRootDir, OutDir { if (!(Test-Path -LiteralPath $DocsRootDir) -or !(Get-ChildItem -LiteralPath $DocsRootDir -Filter *.md -Recurse)) { "No markdown help files to process. Skipping BuildDocs task." return } foreach ($locale in (Get-ChildItem -Path $DocsRootDir -Directory).Name) { - New-ExternalHelp -Path $DocsRootDir\$locale -OutputPath $PublishDir\$locale -Force -ErrorAction SilentlyContinue | Out-Null + New-ExternalHelp -Path $DocsRootDir\$locale -OutputPath $OutDir\$locale -Force -ErrorAction SilentlyContinue | Out-Null } } -Task Install -depends BuildDocs { +Task Install -depends InstallImpl, PostInstall { +} + +Task InstallImpl -depends BuildHelp, PreInstall -requiredVariables OutDir { if ($null -eq $InstallPath) { - # The default installation path is the user's PSModulePath + # The default installation path is the current user's module path. + $moduleInfo = Test-ModuleManifest -Path $SrcRootDir\$ModuleName.psd1 $InstallPath = Join-Path -Path (Split-Path $profile.CurrentUserAllHosts -Parent) ` - -ChildPath "Modules\$ModuleName\$($ModuleDetails.Version.ToString())" + -ChildPath "Modules\$ModuleName\$($moduleInfo.Version.ToString())" } if (!(Test-Path -Path $InstallPath)) { @@ -279,16 +191,16 @@ Task Install -depends BuildDocs { New-Item -Path $InstallPath -ItemType Directory -Verbose:$VerbosePreference > $null } - Copy-Item -Path $PublishDir\* -Destination $InstallPath -Verbose:$VerbosePreference -Recurse -Force + Copy-Item -Path $OutDir\* -Destination $InstallPath -Verbose:$VerbosePreference -Recurse -Force } -Task Test -depends Build { +Task Test -depends Build -requiredVariables TestRootDir, ModuleName { Import-Module Pester try { Microsoft.PowerShell.Management\Push-Location -LiteralPath $TestRootDir - if ($TestOutputFile -ne $null) { + if ($TestOutputFile) { $TestResult = Invoke-Pester -OutputFile $TestOutputFile -OutputFormat $TestOutputFormat -PassThru -Verbose:$VerbosePreference } else { @@ -299,16 +211,16 @@ Task Test -depends Build { } finally { Microsoft.PowerShell.Management\Pop-Location - Remove-Module $ModuleName + Remove-Module $ModuleName -ErrorAction SilentlyContinue } } Task Publish -depends Test, PrePublish, PublishImpl, PostPublish { } -Task PublishImpl -depends Test -requiredVariables SettingsPath, PublishDir { +Task PublishImpl -requiredVariables SettingsPath, OutDir { $publishParams = @{ - Path = $PublishDir + Path = $OutDir NuGetApiKey = $NuGetApiKey } @@ -332,7 +244,7 @@ Task PublishImpl -depends Test -requiredVariables SettingsPath, PublishDir { } $publishParams = @{ - Path = $PublishDir + Path = $OutDir NuGetApiKey = $NuGetApiKey } @@ -350,7 +262,6 @@ Task PublishImpl -depends Test -requiredVariables SettingsPath, PublishDir { Publish-Module @publishParams } - ############################################################################### # Secondary/utility tasks - typically used to manage stored build settings. ############################################################################### @@ -434,7 +345,6 @@ Task ShowCertSubjectName -requiredVariables SettingsPath { } } - ############################################################################### # Helper functions ############################################################################### diff --git a/src/Templates/NewModule/build.settings.ps1 b/src/Templates/NewModule/build.settings.ps1 new file mode 100644 index 0000000..a7f2aac --- /dev/null +++ b/src/Templates/NewModule/build.settings.ps1 @@ -0,0 +1,133 @@ +############################################################################### +# Customize these properties and tasks for your module. +############################################################################### + +Properties { + # ----------------------- Basic properties -------------------------------- + + # The root directories for the module's docs, src and test. + $DocsRootDir = "$PSScriptRoot/docs" + $SrcRootDir = "$PSScriptRoot/src" + $TestRootDir = "$PSScriptRoot/test" + + # The name of your module should match the basename of the PSD1 file. + $ModuleName = Get-Item $SrcRootDir/*.psd1 | + Where-Object { $null -ne (Test-ModuleManifest -Path $_ -ErrorAction SilentlyContinue) } | + Select-Object -First 1 | Foreach-Object BaseName + + # The $OutDir must match the ModuleName in order to support publishing the module. + $ReleaseDir = "$PSScriptRoot/Release" + $OutDir = "$ReleaseDir/$ModuleName" + + # Default Locale used for documentation generatioon, defaults to en-US. + $DefaultLocale = $null + + # Items in the $Exclude array will not be copied to the $OutDir e.g. $Exclude = @('.gitattributes') + # Typically you wouldn't put any file under the src dir unless the file was going to ship with + # the module. However, if there are such files, add their $SrcRootDir relative paths to the exclude list. + $Exclude = @() + + + # ------------------- Script signing properties --------------------------- + + # Set to $true if you want to sign your scripts. You will need to have a code-signing certificate. + # You can specify the certificate's subject name below. If not specified, you will be prompted to + # provide either a subject name or path to a PFX file. After this one time prompt, the value will + # saved for future use and you will no longer be prompted. + $SignScripts = $false + + # Specify the Subject Name of the certificate used to sign your scripts. Leave it as $null and the + # first time you build, you will be prompted to enter your code-signing certificate's Subject Name. + # This variable is used only if $SignScripts is set to $true. + # + # This does require the code-signing certificate to be installed to your certificate store. If you + # have a code-signing certificate in a PFX file, install the certificate to your certificate store + # with the command below. You may be prompted for the certificate's password. + # + # Import-PfxCertificate -FilePath .\myCodeSigingCert.pfx -CertStoreLocation Cert:\CurrentUser\My + # + $CertSubjectName = $null + + + # -------------------- Publishing properties ------------------------------ + + # Your NuGet API key for the PSGallery. Leave it as $null and the first time you publish, + # you will be prompted to enter your API key. The build will store the key encrypted in the + # settings file, so that on subsequent publishes you will no longer be prompted for the API key. + $NuGetApiKey = $null + + # Name of the repository you wish to publish to. If $null is specified the default repo (PowerShellGallery) is used. + $PublishRepository = $null + + # Path to the release notes file. Set to $null if the release notes reside in the manifest file. + # The contents of this file are used during publishing for the ReleaseNotes parameter. + $ReleaseNotesPath = "$PSScriptRoot/ReleaseNotes.md" + + + # ----------------------- Misc properties --------------------------------- + + # In addition, PFX certificates are supported in an interactive scenario only, + # as a way to import a certificate into the user personal store for later use. + # This can be provided using the CertPfxPath parameter. PFX passwords will not be stored. + $SettingsPath = "$env:LOCALAPPDATA\Plaster\NewModuleTemplate\SecuredBuildSettings.clixml" + + # The local installation directory for the install task. Defaults to your user PSModulePath. + $InstallPath = $null + + # Specifies an output file path to send to Invoke-Pester's -OutputFile parameter. + # This is typically used to write out test results so that they can be sent to a CI + # system like AppVeyor. + $TestOutputFile = $null + + # Specifies the test output format to use when the TestOutputFile property is given + # a path. This parameter is passed through to Invoke-Pester's -OutputFormat parameter. + $TestOutputFormat = "NUnitXml" +} + +############################################################################### +# Customize these tasks for performing operations before and/or after Build. +############################################################################### + +# Executes before the BuildImpl phase of the Build task. +Task PreBuild { +} + +# Executes after the Sign phase of the Build task. +Task PostBuild { +} + +############################################################################### +# Customize these tasks for performing operations before and/or after BuildHelp. +############################################################################### + +# Executes before the GenerateMarkdown phase of the BuildHelp task. +Task PreBuildHelp { +} + +# Executes after the BuildHelpImpl phase of the BuildHelp task. +Task PostBuildHelp { +} + +############################################################################### +# Customize these tasks for performing operations before and/or after Install. +############################################################################### + +# Executes before the InstallImpl phase of the Install task. +Task PreInstall { +} + +# Executes after the InstallImpl phase of the Install task. +Task PostInstall { +} + +############################################################################### +# Customize these tasks for performing operations before and/or after Publish. +############################################################################### + +# Executes before publishing occurs. +Task PrePublish { +} + +# Executes after publishing occurs. +Task PostPublish { +} diff --git a/src/Templates/NewModule/editor/VSCode/tasks.json b/src/Templates/NewModule/editor/VSCode/tasks.json index 7de6a3f..fc4734a 100644 --- a/src/Templates/NewModule/editor/VSCode/tasks.json +++ b/src/Templates/NewModule/editor/VSCode/tasks.json @@ -42,6 +42,15 @@ "Invoke-Command { Write-Host 'Completed Build task in task runner.' }" ] }, + { + "taskName": "BuildHelp", + "suppressTaskName": true, + "showOutput": "always", + "args": [ + "Write-Host 'Invoking psake...'; Invoke-psake build.psake.ps1 -taskList BuildHelp;", + "Invoke-Command { Write-Host 'Completed BuildHelp task in task runner.' }" + ] + }, { "taskName": "Install", "suppressTaskName": true, diff --git a/src/Templates/NewModule/plasterManifest.xml b/src/Templates/NewModule/plasterManifest.xml index 3560596..a4cd36d 100644 --- a/src/Templates/NewModule/plasterManifest.xml +++ b/src/Templates/NewModule/plasterManifest.xml @@ -30,7 +30,7 @@ From d4ebc29bbe397e0946ea75e29aac637afcdb1ceb Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Fri, 7 Oct 2016 08:43:44 -0600 Subject: [PATCH 2/2] Eliminate 28 script analyzer warnings. --- build.settings.ps1 | 14 ++++++++++++++ src/Templates/NewModule/build.settings.ps1 | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/build.settings.ps1 b/build.settings.ps1 index a7f2aac..647b388 100644 --- a/build.settings.ps1 +++ b/build.settings.ps1 @@ -6,8 +6,10 @@ Properties { # ----------------------- Basic properties -------------------------------- # The root directories for the module's docs, src and test. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='DocsRootDir')] $DocsRootDir = "$PSScriptRoot/docs" $SrcRootDir = "$PSScriptRoot/src" + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='TestRootDir')] $TestRootDir = "$PSScriptRoot/test" # The name of your module should match the basename of the PSD1 file. @@ -17,14 +19,17 @@ Properties { # The $OutDir must match the ModuleName in order to support publishing the module. $ReleaseDir = "$PSScriptRoot/Release" + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='OutDir')] $OutDir = "$ReleaseDir/$ModuleName" # Default Locale used for documentation generatioon, defaults to en-US. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='DefaultLocale')] $DefaultLocale = $null # Items in the $Exclude array will not be copied to the $OutDir e.g. $Exclude = @('.gitattributes') # Typically you wouldn't put any file under the src dir unless the file was going to ship with # the module. However, if there are such files, add their $SrcRootDir relative paths to the exclude list. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='Exclude')] $Exclude = @() @@ -34,6 +39,7 @@ Properties { # You can specify the certificate's subject name below. If not specified, you will be prompted to # provide either a subject name or path to a PFX file. After this one time prompt, the value will # saved for future use and you will no longer be prompted. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='SignScripts')] $SignScripts = $false # Specify the Subject Name of the certificate used to sign your scripts. Leave it as $null and the @@ -46,6 +52,7 @@ Properties { # # Import-PfxCertificate -FilePath .\myCodeSigingCert.pfx -CertStoreLocation Cert:\CurrentUser\My # + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='CertSubjectName')] $CertSubjectName = $null @@ -54,13 +61,16 @@ Properties { # Your NuGet API key for the PSGallery. Leave it as $null and the first time you publish, # you will be prompted to enter your API key. The build will store the key encrypted in the # settings file, so that on subsequent publishes you will no longer be prompted for the API key. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='NuGetApiKey')] $NuGetApiKey = $null # Name of the repository you wish to publish to. If $null is specified the default repo (PowerShellGallery) is used. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='PublishRepository')] $PublishRepository = $null # Path to the release notes file. Set to $null if the release notes reside in the manifest file. # The contents of this file are used during publishing for the ReleaseNotes parameter. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='ReleaseNotesPath')] $ReleaseNotesPath = "$PSScriptRoot/ReleaseNotes.md" @@ -69,18 +79,22 @@ Properties { # In addition, PFX certificates are supported in an interactive scenario only, # as a way to import a certificate into the user personal store for later use. # This can be provided using the CertPfxPath parameter. PFX passwords will not be stored. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='SettingsPath')] $SettingsPath = "$env:LOCALAPPDATA\Plaster\NewModuleTemplate\SecuredBuildSettings.clixml" # The local installation directory for the install task. Defaults to your user PSModulePath. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='InstallPath')] $InstallPath = $null # Specifies an output file path to send to Invoke-Pester's -OutputFile parameter. # This is typically used to write out test results so that they can be sent to a CI # system like AppVeyor. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='TestOutputFile')] $TestOutputFile = $null # Specifies the test output format to use when the TestOutputFile property is given # a path. This parameter is passed through to Invoke-Pester's -OutputFormat parameter. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='TestOutputFormat')] $TestOutputFormat = "NUnitXml" } diff --git a/src/Templates/NewModule/build.settings.ps1 b/src/Templates/NewModule/build.settings.ps1 index a7f2aac..647b388 100644 --- a/src/Templates/NewModule/build.settings.ps1 +++ b/src/Templates/NewModule/build.settings.ps1 @@ -6,8 +6,10 @@ Properties { # ----------------------- Basic properties -------------------------------- # The root directories for the module's docs, src and test. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='DocsRootDir')] $DocsRootDir = "$PSScriptRoot/docs" $SrcRootDir = "$PSScriptRoot/src" + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='TestRootDir')] $TestRootDir = "$PSScriptRoot/test" # The name of your module should match the basename of the PSD1 file. @@ -17,14 +19,17 @@ Properties { # The $OutDir must match the ModuleName in order to support publishing the module. $ReleaseDir = "$PSScriptRoot/Release" + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='OutDir')] $OutDir = "$ReleaseDir/$ModuleName" # Default Locale used for documentation generatioon, defaults to en-US. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='DefaultLocale')] $DefaultLocale = $null # Items in the $Exclude array will not be copied to the $OutDir e.g. $Exclude = @('.gitattributes') # Typically you wouldn't put any file under the src dir unless the file was going to ship with # the module. However, if there are such files, add their $SrcRootDir relative paths to the exclude list. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='Exclude')] $Exclude = @() @@ -34,6 +39,7 @@ Properties { # You can specify the certificate's subject name below. If not specified, you will be prompted to # provide either a subject name or path to a PFX file. After this one time prompt, the value will # saved for future use and you will no longer be prompted. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='SignScripts')] $SignScripts = $false # Specify the Subject Name of the certificate used to sign your scripts. Leave it as $null and the @@ -46,6 +52,7 @@ Properties { # # Import-PfxCertificate -FilePath .\myCodeSigingCert.pfx -CertStoreLocation Cert:\CurrentUser\My # + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='CertSubjectName')] $CertSubjectName = $null @@ -54,13 +61,16 @@ Properties { # Your NuGet API key for the PSGallery. Leave it as $null and the first time you publish, # you will be prompted to enter your API key. The build will store the key encrypted in the # settings file, so that on subsequent publishes you will no longer be prompted for the API key. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='NuGetApiKey')] $NuGetApiKey = $null # Name of the repository you wish to publish to. If $null is specified the default repo (PowerShellGallery) is used. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='PublishRepository')] $PublishRepository = $null # Path to the release notes file. Set to $null if the release notes reside in the manifest file. # The contents of this file are used during publishing for the ReleaseNotes parameter. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='ReleaseNotesPath')] $ReleaseNotesPath = "$PSScriptRoot/ReleaseNotes.md" @@ -69,18 +79,22 @@ Properties { # In addition, PFX certificates are supported in an interactive scenario only, # as a way to import a certificate into the user personal store for later use. # This can be provided using the CertPfxPath parameter. PFX passwords will not be stored. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='SettingsPath')] $SettingsPath = "$env:LOCALAPPDATA\Plaster\NewModuleTemplate\SecuredBuildSettings.clixml" # The local installation directory for the install task. Defaults to your user PSModulePath. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='InstallPath')] $InstallPath = $null # Specifies an output file path to send to Invoke-Pester's -OutputFile parameter. # This is typically used to write out test results so that they can be sent to a CI # system like AppVeyor. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='TestOutputFile')] $TestOutputFile = $null # Specifies the test output format to use when the TestOutputFile property is given # a path. This parameter is passed through to Invoke-Pester's -OutputFormat parameter. + [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '', Scope='*', Target='TestOutputFormat')] $TestOutputFormat = "NUnitXml" }