@@ -93,14 +93,11 @@ function Start-DocumentationBuild
9393 $docsPath = Join-Path $projectRoot docs
9494 $markdownDocsPath = Join-Path $docsPath markdown
9595 $outputDocsPath = Join-Path $destinationDir en- US
96- $requiredVersionOfplatyPS = 0.9
97- # $modInfo = new-object Microsoft.PowerShell.Commands.ModuleSpecification -ArgumentList @{ ModuleName = "platyps"; ModuleVersion = $requiredVersionOfplatyPS}
98- # if ( $null -eq (Get-Module -ListAvailable -FullyQualifiedName $modInfo))
99- if ( $null -eq (Get-Module - ListAvailable platyPS))
96+ $platyPS = Get-Module - ListAvailable platyPS
97+ if ($null -eq $platyPS -or ($platyPS | Sort-Object Version - Descending | Select-Object - First 1 ).Version -lt [version ]0.12 )
10098 {
101- Write-Verbose - verbose " platyPS not found, installing"
99+ Write-Verbose - verbose " platyPS module not found or below required version of 0.12 , installing the latest version. "
102100 Install-Module - Force - Name platyPS - Scope CurrentUser
103- # throw "Cannot find required minimum version $requiredVersionOfplatyPS of platyPS. Install via 'Install-Module platyPS'"
104101 }
105102 if (-not (Test-Path $markdownDocsPath ))
106103 {
@@ -118,65 +115,42 @@ function Start-ScriptAnalyzerBuild
118115{
119116 [CmdletBinding (DefaultParameterSetName = " BuildOne" )]
120117 param (
121- [Parameter (ParameterSetName = " BuildAll" )]
122118 [switch ]$All ,
123119
124- [Parameter (ParameterSetName = " BuildOne" )]
125- [ValidateSet (" full" , " core" )]
126- [string ]$Framework = " core" ,
120+ [ValidateRange (3 , 6 )]
121+ [int ]$PSVersion = $PSVersionTable.PSVersion.Major ,
127122
128- [Parameter (ParameterSetName = " BuildOne" )]
129- [ValidateSet (" 3" , " 4" , " 5" )]
130- [string ]$PSVersion = " 5" ,
131-
132- [Parameter (ParameterSetName = " BuildOne" )]
133- [Parameter (ParameterSetName = " BuildAll" )]
134123 [ValidateSet (" Debug" , " Release" )]
135124 [string ]$Configuration = " Debug" ,
136125
137- [Parameter (ParameterSetName = " BuildDoc" )]
138126 [switch ]$Documentation
139127 )
140128
141- BEGIN {
142- if ( $PSVersion -match " [34]" -and $Framework -eq " core" ) {
143- throw " Script Analyzer for PowerShell 3/4 cannot be built for framework 'core'"
144- }
145- }
146129 END {
147130 if ( $All )
148131 {
149132 # Build all the versions of the analyzer
150- Start-ScriptAnalyzerBuild - Framework full - Configuration $Configuration - PSVersion " 3"
151- Start-ScriptAnalyzerBuild - Framework full - Configuration $Configuration - PSVersion " 4"
152- Start-ScriptAnalyzerBuild - Framework full - Configuration $Configuration - PSVersion " 5"
153- Start-ScriptAnalyzerBuild - Framework core - Configuration $Configuration - PSVersion " 5"
154- Start-ScriptAnalyzerBuild - Documentation
133+ foreach ($psVersion in 3 .. 6 ) {
134+ Start-ScriptAnalyzerBuild - Configuration $Configuration - PSVersion $psVersion
135+ }
155136 return
156137 }
157138
158- if ( $Documentation )
139+ $documentationFileExists = Test-Path (Join-Path $PSScriptRoot ' out\PSScriptAnalyzer\en-us\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll-Help.xml' )
140+ # Build docs either when -Documentation switch is being specified or the first time in a clean repo
141+ if ( $Documentation -or -not $documentationFileExists )
159142 {
160143 Start-DocumentationBuild
161- return
162144 }
163145
164- Push-Location - Path $projectRoot
165-
166- if ( $framework -eq " core" ) {
167- $frameworkName = " netstandard2.0"
146+ if ($PSVersion -ge 6 ) {
147+ $framework = ' netstandard2.0'
168148 }
169149 else {
170- $frameworkName = " net452"
171- }
172-
173- # build the appropriate assembly
174- if ($PSVersion -match " [34]" -and $Framework -eq " core" )
175- {
176- throw (" ScriptAnalyzer for PS version '{0}' is not applicable to {1} framework" -f $PSVersion , $Framework )
150+ $framework = " net452"
177151 }
178152
179- # Write-Progress "Building ScriptAnalyzer"
153+ Push-Location - Path $projectRoot
180154 if (-not (Test-Path " $projectRoot /global.json" ))
181155 {
182156 throw " Not in solution root"
@@ -188,53 +162,61 @@ function Start-ScriptAnalyzerBuild
188162 )
189163
190164 $destinationDir = " $projectRoot \out\PSScriptAnalyzer"
191- # this is normalizing case as well as selecting the proper location
192- if ( $Framework -eq " core" ) {
193- $destinationDirBinaries = " $destinationDir \coreclr"
194- }
195- elseif ($PSVersion -eq ' 3' ) {
196- $destinationDirBinaries = " $destinationDir \PSv3"
197- }
198- elseif ($PSVersion -eq ' 4' ) {
199- $destinationDirBinaries = " $destinationDir \PSv4"
200- }
201- else {
202- $destinationDirBinaries = $destinationDir
165+ switch ($PSVersion )
166+ {
167+ 3
168+ {
169+ $destinationDirBinaries = " $destinationDir \PSv3"
170+ }
171+ 4
172+ {
173+ $destinationDirBinaries = " $destinationDir \PSv4"
174+ }
175+ 5
176+ {
177+ $destinationDirBinaries = " $destinationDir "
178+ }
179+ 6
180+ {
181+ $destinationDirBinaries = " $destinationDir \coreclr"
182+ }
183+ default
184+ {
185+ throw " Unsupported PSVersion: '$PSVersion '"
186+ }
203187 }
204188
205- # build the analyzer
206- # Write-Progress "Building for framework $Framework, configuration $Configuration"
207- # The Rules project has a dependency on the Engine therefore just building the Rules project is enough
208189 $config = " PSV${PSVersion}${Configuration} "
190+
191+ # Build ScriptAnalyzer
192+ # The Rules project has a dependency on the Engine therefore just building the Rules project is enough
209193 try {
210194 Push-Location $projectRoot / Rules
211- Write-Progress " Building ScriptAnalyzer ' $framework ' version ' ${PSVersion} ' configuration '${ Configuration} '"
212- $buildOutput = dotnet build Rules.csproj -- framework $frameworkName -- configuration " ${ config} "
195+ Write-Progress " Building ScriptAnalyzer for PSVersion ' $PSVersion ' using framework ' $framework ' and configuration '$Configuration '"
196+ $buildOutput = dotnet build -- framework $framework -- configuration " $config "
213197 if ( $LASTEXITCODE -ne 0 ) { throw " $buildOutput " }
214198 }
215199 catch {
216- Write-Error " Failure to build $ framework ${ config} "
200+ Write-Error " Failure to build for PSVersion ' $PSVersion ' using framework ' $framework ' and configuration ' $ config' "
217201 return
218202 }
219203 finally {
220204 Pop-Location
221205 }
222206
223- # Write-Progress "Copying files to $destinationDir"
224207 Publish-File $itemsToCopyCommon $destinationDir
225208
226209 $itemsToCopyBinaries = @ (
227- " $projectRoot \Engine\bin\${config} \${frameworkName } \Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" ,
228- " $projectRoot \Rules\bin\${config} \${frameworkName } \Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll"
210+ " $projectRoot \Engine\bin\${config} \${framework } \Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" ,
211+ " $projectRoot \Rules\bin\${config} \${framework } \Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll"
229212 )
230213 Publish-File $itemsToCopyBinaries $destinationDirBinaries
231214
232215 $settingsFiles = Get-Childitem " $projectRoot \Engine\Settings" | ForEach-Object - MemberName FullName
233216 Publish-File $settingsFiles (Join-Path - Path $destinationDir - ChildPath Settings)
234217
235- # copy newtonsoft dll if net452 framework
236- if ($Framework -eq " full" ) {
237- Copy-Item - path " $projectRoot \Rules\bin\${config} \${frameworkName} \Newtonsoft.Json.dll" - Destination $destinationDirBinaries
218+ if ($framework -eq ' net452' ) {
219+ Copy-Item - path " $projectRoot \Rules\bin\${config} \${framework} \Newtonsoft.Json.dll" - Destination $destinationDirBinaries
238220 }
239221
240222 Pop-Location
@@ -255,7 +237,7 @@ function Test-ScriptAnalyzer
255237 try {
256238 $savedModulePath = $env: PSModulePath
257239 $env: PSModulePath = " ${testModulePath} {0}${env: PSModulePath} " -f [System.IO.Path ]::PathSeparator
258- $scriptBlock = [scriptblock ]::Create(" Invoke-Pester -Path $testScripts -OutputFormat NUnitXml -OutputFile $testResultsFile -Show Describe" )
240+ $scriptBlock = [scriptblock ]::Create(" Invoke-Pester -Path $testScripts -OutputFormat NUnitXml -OutputFile $testResultsFile -Show Describe,Summary " )
259241 if ( $InProcess ) {
260242 & $scriptBlock
261243 }
0 commit comments