Skip to content

Commit f46abf3

Browse files
committed
change to use psversion rather than analyzerversion
because it's really about the version of PS, not the analyzer
1 parent 3064367 commit f46abf3

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ Note: the PSScriptAnalyzer Chocolatey package is provided and supported by the c
129129
```
130130
* Windows PowerShell version 5.0
131131
```powershell
132-
.\build.ps1 -Framework full -AnalyzerVersion PSV5 -Configuration Release
132+
.\build.ps1 -Framework full -PSVersion 5 -Configuration Release
133133
```
134134
* Windows PowerShell version 4.0
135135
```powershell
136-
.\build.ps1 -Framework full -AnalyzerVersion PSV4 -Configuration Release
136+
.\build.ps1 -Framework full -PSVersion 4 -Configuration Release
137137
```
138138
* Windows PowerShell version 3.0
139139
```powershell
140-
.\build.ps1 -Framework full -AnalyzerVersion PSV3 -Configuration Release
140+
.\build.ps1 -Framework full -PSVersion 3 -Configuration Release
141141
```
142142
* PowerShell Core
143143
```powershell

build.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ param(
88
[string]$Framework = "core",
99

1010
[Parameter(ParameterSetName="BuildOne")]
11-
[ValidateSet("PSv3","PSv4","PSv5")]
12-
[string]$AnalyzerVersion = "PSv5",
11+
[ValidateSet("3","4","5")]
12+
[string]$PSVersion = "5",
1313

1414
[Parameter(ParameterSetName="BuildOne")]
15+
[Parameter(ParameterSetName="BuildAll")]
1516
[ValidateSet("Debug", "Release")]
1617
[string]$Configuration = "Debug",
1718

@@ -44,15 +45,15 @@ END {
4445
$setName = $PSCmdlet.ParameterSetName
4546
switch ( $setName ) {
4647
"BuildAll" {
47-
Build-ScriptAnalyzer -All
48+
Build-ScriptAnalyzer -All -Configuration $Configuration
4849
}
4950
"BuildDoc" {
5051
Build-ScriptAnalyzer -Documentation
5152
}
5253
"BuildOne" {
5354
$buildArgs = @{
5455
Framework = $Framework
55-
AnalyzerVersion = $AnalyzerVersion
56+
PSVersion = $PSVersion
5657
Configuration = $Configuration
5758
}
5859
Build-ScriptAnalyzer @buildArgs
@@ -65,4 +66,4 @@ END {
6566
throw "Unexpected parameter set '$setName'"
6667
}
6768
}
68-
}
69+
}

build.psm1

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)