@@ -121,25 +121,31 @@ function Build-ScriptAnalyzer
121121 [string ]$Framework = " core" ,
122122
123123 [Parameter (ParameterSetName = " BuildOne" )]
124- [ValidateSet (" PSv3 " , " PSv4 " , " PSv5 " )]
125- [string ]$AnalyzerVersion = " PSv5 " ,
124+ [ValidateSet (" 3 " , " 4 " , " 5 " )]
125+ [string ]$PSVersion = " 5 " ,
126126
127127 [Parameter (ParameterSetName = " BuildOne" )]
128+ [Parameter (ParameterSetName = " BuildAll" )]
128129 [ValidateSet (" Debug" , " Release" )]
129130 [string ]$Configuration = " Debug" ,
130131
131132 [Parameter (ParameterSetName = " BuildDoc" )]
132133 [switch ]$Documentation
133134 )
134135
136+ BEGIN {
137+ if ( $PSVersion -match " [34]" -and $Framework -eq " core" ) {
138+ throw " Script Analyzer for PowerShell 3/4 cannot be built for framework 'core'"
139+ }
140+ }
135141 END {
136142 if ( $All )
137143 {
138144 # Build all the versions of the analyzer
139- Build-ScriptAnalyzer - Framework full - Configuration $Configuration - AnalyzerVersion " PSv3 "
140- Build-ScriptAnalyzer - Framework full - Configuration $Configuration - AnalyzerVersion " PSv4 "
141- Build-ScriptAnalyzer - Framework full - Configuration $Configuration - AnalyzerVersion " PSv5 "
142- Build-ScriptAnalyzer - Framework core - Configuration $Configuration - AnalyzerVersion " PSv5 "
145+ Build-ScriptAnalyzer - Framework full - Configuration $Configuration - PSVersion " 3 "
146+ Build-ScriptAnalyzer - Framework full - Configuration $Configuration - PSVersion " 4 "
147+ Build-ScriptAnalyzer - Framework full - Configuration $Configuration - PSVersion " 5 "
148+ Build-ScriptAnalyzer - Framework core - Configuration $Configuration - PSVersion " 5 "
143149 Build-ScriptAnalyzer - Documentation
144150 return
145151 }
@@ -160,9 +166,9 @@ function Build-ScriptAnalyzer
160166 }
161167
162168 # build the appropriate assembly
163- if ($AnalyzerVersion -match " PSv3|PSv4 " -and $Framework -eq " core" )
169+ if ($PSVersion -match " [34] " -and $Framework -eq " core" )
164170 {
165- throw (" ScriptAnalyzer Version '{0}' is not applicable to {1} framework" -f $AnalyzerVersion , $Framework )
171+ throw (" ScriptAnalyzer for PS version '{0}' is not applicable to {1} framework" -f $PSVersion , $Framework )
166172 }
167173
168174 # Write-Progress "Building ScriptAnalyzer"
@@ -183,10 +189,10 @@ function Build-ScriptAnalyzer
183189 if ( $Framework -eq " core" ) {
184190 $destinationDirBinaries = " $destinationDir \coreclr"
185191 }
186- elseif ($AnalyzerVersion -eq ' PSv3 ' ) {
192+ elseif ($PSVersion -eq ' 3 ' ) {
187193 $destinationDirBinaries = " $destinationDir \PSv3"
188194 }
189- elseif ($AnalyzerVersion -eq ' PSv4 ' ) {
195+ elseif ($PSVersion -eq ' 4 ' ) {
190196 $destinationDirBinaries = " $destinationDir \PSv4"
191197 }
192198 else {
@@ -198,12 +204,12 @@ function Build-ScriptAnalyzer
198204 # The Rules project has a dependency on the Engine therefore just building the Rules project is enough
199205 try {
200206 Push-Location $projectRoot / Rules
201- Write-Progress " Building ScriptAnalyzer '$framework ' version '${AnalyzerVersion } ' configuration '${Configuration} '"
202- $buildOutput = dotnet build Rules.csproj -- framework $frameworkName -- configuration " ${AnalyzerVersion }${Configuration} "
207+ Write-Progress " Building ScriptAnalyzer '$framework ' version '${PSVersion } ' configuration '${Configuration} '"
208+ $buildOutput = dotnet build Rules.csproj -- framework $frameworkName -- configuration " ${PSVersion }${Configuration} "
203209 if ( $LASTEXITCODE -ne 0 ) { throw " $buildOutput " }
204210 }
205211 catch {
206- Write-Error " Failure to build $framework ${AnalyzerVersion }${Configuration} "
212+ Write-Error " Failure to build $framework ${PSVersion }${Configuration} "
207213 return
208214 }
209215 finally {
@@ -214,16 +220,16 @@ function Build-ScriptAnalyzer
214220 Publish-File $itemsToCopyCommon $destinationDir
215221
216222 $itemsToCopyBinaries = @ (
217- " $projectRoot \Engine\bin\${AnalyzerVersion }${Configuration} \${frameworkName} \Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" ,
218- " $projectRoot \Rules\bin\${AnalyzerVersion }${Configuration} \${frameworkName} \Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll"
223+ " $projectRoot \Engine\bin\${PSVersion }${Configuration} \${frameworkName} \Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" ,
224+ " $projectRoot \Rules\bin\${PSVersion }${Configuration} \${frameworkName} \Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll"
219225 )
220226 Publish-File $itemsToCopyBinaries $destinationDirBinaries
221227
222228 Publish-File $settingsFiles (Join-Path - Path $destinationDir - ChildPath Settings)
223229
224230 # copy newtonsoft dll if net451 framework
225231 if ($Framework -eq " full" ) {
226- Copy-Item - path " $projectRoot \Rules\bin\${AnalyzerVersion }${Configuration} \${frameworkName} \Newtonsoft.Json.dll" - Destination $destinationDirBinaries
232+ Copy-Item - path " $projectRoot \Rules\bin\${PSVersion }${Configuration} \${frameworkName} \Newtonsoft.Json.dll" - Destination $destinationDirBinaries
227233 }
228234
229235 Pop-Location
0 commit comments