@@ -121,25 +121,31 @@ function Build-ScriptAnalyzer
121
121
[string ]$Framework = " core" ,
122
122
123
123
[Parameter (ParameterSetName = " BuildOne" )]
124
- [ValidateSet (" PSv3 " , " PSv4 " , " PSv5 " )]
125
- [string ]$AnalyzerVersion = " PSv5 " ,
124
+ [ValidateSet (" 3 " , " 4 " , " 5 " )]
125
+ [string ]$PSVersion = " 5 " ,
126
126
127
127
[Parameter (ParameterSetName = " BuildOne" )]
128
+ [Parameter (ParameterSetName = " BuildAll" )]
128
129
[ValidateSet (" Debug" , " Release" )]
129
130
[string ]$Configuration = " Debug" ,
130
131
131
132
[Parameter (ParameterSetName = " BuildDoc" )]
132
133
[switch ]$Documentation
133
134
)
134
135
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
+ }
135
141
END {
136
142
if ( $All )
137
143
{
138
144
# 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 "
143
149
Build-ScriptAnalyzer - Documentation
144
150
return
145
151
}
@@ -160,9 +166,9 @@ function Build-ScriptAnalyzer
160
166
}
161
167
162
168
# build the appropriate assembly
163
- if ($AnalyzerVersion -match " PSv3|PSv4 " -and $Framework -eq " core" )
169
+ if ($PSVersion -match " [34] " -and $Framework -eq " core" )
164
170
{
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 )
166
172
}
167
173
168
174
# Write-Progress "Building ScriptAnalyzer"
@@ -183,10 +189,10 @@ function Build-ScriptAnalyzer
183
189
if ( $Framework -eq " core" ) {
184
190
$destinationDirBinaries = " $destinationDir \coreclr"
185
191
}
186
- elseif ($AnalyzerVersion -eq ' PSv3 ' ) {
192
+ elseif ($PSVersion -eq ' 3 ' ) {
187
193
$destinationDirBinaries = " $destinationDir \PSv3"
188
194
}
189
- elseif ($AnalyzerVersion -eq ' PSv4 ' ) {
195
+ elseif ($PSVersion -eq ' 4 ' ) {
190
196
$destinationDirBinaries = " $destinationDir \PSv4"
191
197
}
192
198
else {
@@ -198,12 +204,12 @@ function Build-ScriptAnalyzer
198
204
# The Rules project has a dependency on the Engine therefore just building the Rules project is enough
199
205
try {
200
206
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} "
203
209
if ( $LASTEXITCODE -ne 0 ) { throw " $buildOutput " }
204
210
}
205
211
catch {
206
- Write-Error " Failure to build $framework ${AnalyzerVersion }${Configuration} "
212
+ Write-Error " Failure to build $framework ${PSVersion }${Configuration} "
207
213
return
208
214
}
209
215
finally {
@@ -214,16 +220,16 @@ function Build-ScriptAnalyzer
214
220
Publish-File $itemsToCopyCommon $destinationDir
215
221
216
222
$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"
219
225
)
220
226
Publish-File $itemsToCopyBinaries $destinationDirBinaries
221
227
222
228
Publish-File $settingsFiles (Join-Path - Path $destinationDir - ChildPath Settings)
223
229
224
230
# copy newtonsoft dll if net451 framework
225
231
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
227
233
}
228
234
229
235
Pop-Location
0 commit comments