@@ -93,14 +93,11 @@ function Start-DocumentationBuild
93
93
$docsPath = Join-Path $projectRoot docs
94
94
$markdownDocsPath = Join-Path $docsPath markdown
95
95
$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 )
100
98
{
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. "
102
100
Install-Module - Force - Name platyPS - Scope CurrentUser
103
- # throw "Cannot find required minimum version $requiredVersionOfplatyPS of platyPS. Install via 'Install-Module platyPS'"
104
101
}
105
102
if (-not (Test-Path $markdownDocsPath ))
106
103
{
@@ -118,65 +115,42 @@ function Start-ScriptAnalyzerBuild
118
115
{
119
116
[CmdletBinding (DefaultParameterSetName = " BuildOne" )]
120
117
param (
121
- [Parameter (ParameterSetName = " BuildAll" )]
122
118
[switch ]$All ,
123
119
124
- [Parameter (ParameterSetName = " BuildOne" )]
125
- [ValidateSet (" full" , " core" )]
126
- [string ]$Framework = " core" ,
120
+ [ValidateRange (3 , 6 )]
121
+ [int ]$PSVersion = $PSVersionTable.PSVersion.Major ,
127
122
128
- [Parameter (ParameterSetName = " BuildOne" )]
129
- [ValidateSet (" 3" , " 4" , " 5" )]
130
- [string ]$PSVersion = " 5" ,
131
-
132
- [Parameter (ParameterSetName = " BuildOne" )]
133
- [Parameter (ParameterSetName = " BuildAll" )]
134
123
[ValidateSet (" Debug" , " Release" )]
135
124
[string ]$Configuration = " Debug" ,
136
125
137
- [Parameter (ParameterSetName = " BuildDoc" )]
138
126
[switch ]$Documentation
139
127
)
140
128
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
- }
146
129
END {
147
130
if ( $All )
148
131
{
149
132
# 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
+ }
155
136
return
156
137
}
157
138
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 )
159
142
{
160
143
Start-DocumentationBuild
161
- return
162
144
}
163
145
164
- Push-Location - Path $projectRoot
165
-
166
- if ( $framework -eq " core" ) {
167
- $frameworkName = " netstandard2.0"
146
+ if ($PSVersion -ge 6 ) {
147
+ $framework = ' netstandard2.0'
168
148
}
169
149
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"
177
151
}
178
152
179
- # Write-Progress "Building ScriptAnalyzer"
153
+ Push-Location - Path $projectRoot
180
154
if (-not (Test-Path " $projectRoot /global.json" ))
181
155
{
182
156
throw " Not in solution root"
@@ -188,53 +162,61 @@ function Start-ScriptAnalyzerBuild
188
162
)
189
163
190
164
$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
+ }
203
187
}
204
188
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
208
189
$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
209
193
try {
210
194
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 "
213
197
if ( $LASTEXITCODE -ne 0 ) { throw " $buildOutput " }
214
198
}
215
199
catch {
216
- Write-Error " Failure to build $ framework ${ config} "
200
+ Write-Error " Failure to build for PSVersion ' $PSVersion ' using framework ' $framework ' and configuration ' $ config' "
217
201
return
218
202
}
219
203
finally {
220
204
Pop-Location
221
205
}
222
206
223
- # Write-Progress "Copying files to $destinationDir"
224
207
Publish-File $itemsToCopyCommon $destinationDir
225
208
226
209
$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"
229
212
)
230
213
Publish-File $itemsToCopyBinaries $destinationDirBinaries
231
214
232
215
$settingsFiles = Get-Childitem " $projectRoot \Engine\Settings" | ForEach-Object - MemberName FullName
233
216
Publish-File $settingsFiles (Join-Path - Path $destinationDir - ChildPath Settings)
234
217
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
238
220
}
239
221
240
222
Pop-Location
@@ -255,7 +237,7 @@ function Test-ScriptAnalyzer
255
237
try {
256
238
$savedModulePath = $env: PSModulePath
257
239
$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 " )
259
241
if ( $InProcess ) {
260
242
& $scriptBlock
261
243
}
0 commit comments