3
3
4
4
# Build module for PowerShell ScriptAnalyzer
5
5
$projectRoot = $PSScriptRoot
6
- $destinationDir = Join-Path - Path $projectRoot - ChildPath (Join-Path - Path " out" - ChildPath " PSScriptAnalyzer" )
6
+ $analyzerName = " PSScriptAnalyzer"
7
+
8
+ function Get-AnalyzerVersion
9
+ {
10
+ $csprojPath = [io.path ]::Combine($projectRoot , " Engine" , " Engine.csproj" )
11
+ $xml = [xml ](Get-Content " ${csprojPath} " )
12
+ $xml.SelectSingleNode (" .//VersionPrefix" )." #text"
13
+ }
14
+
15
+ $analyzerVersion = Get-AnalyzerVersion
16
+ # location where analyzer goes
17
+ $script :destinationDir = [io.path ]::Combine($projectRoot , " out" , " ${analyzerName} " , $analyzerVersion )
7
18
8
19
function Publish-File
9
20
{
@@ -40,7 +51,7 @@ function Get-UserModulePath
40
51
function Uninstall-ScriptAnalyzer
41
52
{
42
53
[CmdletBinding (SupportsShouldProcess )]
43
- param ( $ModulePath = $ (Join-Path - Path (Get-UserModulePath ) - ChildPath PSScriptAnalyzer ) )
54
+ param ( $ModulePath = $ (Join-Path - Path (Get-UserModulePath ) - ChildPath ${analyzerName} ) )
44
55
END {
45
56
if ( $PSCmdlet.ShouldProcess (" $modulePath " ) ) {
46
57
Remove-Item - Recurse - Path " $ModulePath " - Force
@@ -52,10 +63,10 @@ function Uninstall-ScriptAnalyzer
52
63
function Install-ScriptAnalyzer
53
64
{
54
65
[CmdletBinding (SupportsShouldProcess )]
55
- param ( $ModulePath = $ (Join-Path - Path (Get-UserModulePath ) - ChildPath PSScriptAnalyzer ) )
66
+ param ( $ModulePath = $ (Join-Path - Path (Get-UserModulePath ) - ChildPath ${analyzerName} ) )
56
67
END {
57
68
if ( $PSCmdlet.ShouldProcess (" $modulePath " ) ) {
58
- Copy-Item - Recurse - Path " $destinationDir " - Destination " $ModulePath \." - Force
69
+ Copy-Item - Recurse - Path " $script : destinationDir " - Destination " $ModulePath \." - Force
59
70
}
60
71
}
61
72
}
@@ -64,7 +75,7 @@ function Install-ScriptAnalyzer
64
75
function Uninstall-ScriptAnalyzer
65
76
{
66
77
[CmdletBinding (SupportsShouldProcess )]
67
- param ( $ModulePath = $ (Join-Path - Path (Get-UserModulePath ) - ChildPath PSScriptAnalyzer ) )
78
+ param ( $ModulePath = $ (Join-Path - Path (Get-UserModulePath ) - ChildPath ${analyzerName} ) )
68
79
END {
69
80
if ((Test-Path $ModulePath ) -and (Get-Item $ModulePath ).PSIsContainer )
70
81
{
@@ -79,9 +90,9 @@ function Remove-Build
79
90
[CmdletBinding (SupportsShouldProcess = $true )]
80
91
param ()
81
92
END {
82
- if ( $PSCmdlet.ShouldProcess (" ${destinationDir} " )) {
83
- if ( Test-Path ${destinationDir} ) {
84
- Remove-Item - Force - Recurse ${destinationDir}
93
+ if ( $PSCmdlet.ShouldProcess (" ${ script: destinationDir } " )) {
94
+ if ( Test-Path ${script : destinationDir} ) {
95
+ Remove-Item - Force - Recurse ${script : destinationDir}
85
96
}
86
97
}
87
98
}
@@ -92,7 +103,7 @@ function Start-DocumentationBuild
92
103
{
93
104
$docsPath = Join-Path $projectRoot docs
94
105
$markdownDocsPath = Join-Path $docsPath markdown
95
- $outputDocsPath = Join-Path $destinationDir en- US
106
+ $outputDocsPath = Join-Path $script : destinationDir en- US
96
107
$platyPS = Get-Module - ListAvailable platyPS
97
108
if ($null -eq $platyPS -or ($platyPS | Sort-Object Version - Descending | Select-Object - First 1 ).Version -lt [version ]0.12 )
98
109
{
@@ -118,12 +129,12 @@ function Copy-CompatibilityProfiles
118
129
}
119
130
120
131
$profileDir = [System.IO.Path ]::Combine($PSScriptRoot , ' PSCompatibilityCollector' , ' profiles' )
121
- $destinationDir = [System.IO.Path ]::Combine($PSScriptRoot , ' out ' , ' PSScriptAnalyzer ' , " compatibility_profiles" )
122
- if ( -not (Test-Path $destinationDir ) ) {
123
- $null = New-Item - Type Directory $destinationDir
132
+ $targetProfileDir = [io.path ]::Combine($script :destinationDir , " compatibility_profiles" )
133
+ if ( -not (Test-Path $targetProfileDir ) ) {
134
+ $null = New-Item - Type Directory $targetProfileDir
124
135
}
125
136
126
- Copy-Item - Force $profileDir /* $destinationDir
137
+ Copy-Item - Force $profileDir /* $targetProfileDir
127
138
}
128
139
129
140
# build script analyzer (and optionally build everything with -All)
@@ -162,9 +173,6 @@ function Start-ScriptAnalyzerBuild
162
173
Start-DocumentationBuild
163
174
}
164
175
165
- # Destination for the composed module when built
166
- $destinationDir = " $projectRoot \out\PSScriptAnalyzer"
167
-
168
176
if ( $All )
169
177
{
170
178
# Build all the versions of the analyzer
@@ -205,24 +213,23 @@ function Start-ScriptAnalyzerBuild
205
213
" $projectRoot \Engine\ScriptAnalyzer.format.ps1xml" , " $projectRoot \Engine\ScriptAnalyzer.types.ps1xml"
206
214
)
207
215
208
- $destinationDir = " $projectRoot \out\PSScriptAnalyzer"
209
216
switch ($PSVersion )
210
217
{
211
218
3
212
219
{
213
- $destinationDirBinaries = " $destinationDir \PSv3"
220
+ $destinationDirBinaries = " $script : destinationDir \PSv3"
214
221
}
215
222
4
216
223
{
217
- $destinationDirBinaries = " $destinationDir \PSv4"
224
+ $destinationDirBinaries = " $script : destinationDir \PSv4"
218
225
}
219
226
5
220
227
{
221
- $destinationDirBinaries = " $destinationDir "
228
+ $destinationDirBinaries = " $script : destinationDir "
222
229
}
223
230
6
224
231
{
225
- $destinationDirBinaries = " $destinationDir \coreclr"
232
+ $destinationDirBinaries = " $script : destinationDir \coreclr"
226
233
}
227
234
default
228
235
{
@@ -252,7 +259,7 @@ function Start-ScriptAnalyzerBuild
252
259
Pop-Location
253
260
}
254
261
255
- Publish-File $itemsToCopyCommon $destinationDir
262
+ Publish-File $itemsToCopyCommon $script : destinationDir
256
263
257
264
$itemsToCopyBinaries = @ (
258
265
" $projectRoot \Engine\bin\${config} \${Framework} \Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" ,
@@ -262,7 +269,7 @@ function Start-ScriptAnalyzerBuild
262
269
Publish-File $itemsToCopyBinaries $destinationDirBinaries
263
270
264
271
$settingsFiles = Get-Childitem " $projectRoot \Engine\Settings" | ForEach-Object - MemberName FullName
265
- Publish-File $settingsFiles (Join-Path - Path $destinationDir - ChildPath Settings)
272
+ Publish-File $settingsFiles (Join-Path - Path $script : destinationDir - ChildPath Settings)
266
273
267
274
if ($framework -eq ' net452' ) {
268
275
Copy-Item - path " $projectRoot \Rules\bin\${config} \${framework} \Newtonsoft.Json.dll" - Destination $destinationDirBinaries
@@ -280,10 +287,38 @@ function Test-ScriptAnalyzer
280
287
param ( [Parameter ()][switch ]$InProcess , [switch ]$ShowAll )
281
288
282
289
END {
283
- $testModulePath = Join-Path " ${projectRoot} " - ChildPath out
290
+ # versions 3 and 4 don't understand versioned module paths, so we need to rename the directory of the version to
291
+ # the module name, and then set the ModulePath to that
292
+ #
293
+ # the layout of the build location is
294
+ # .../out
295
+ # /PSScriptAnalyzer
296
+ # /1.18.0
297
+ # /<modulefiles live here>
298
+ # and ".../out" is added to env:PSModulePath
299
+ # on v3 and v4, it will be
300
+ # .../out
301
+ # /PSScriptAnalyzer
302
+ # /PSScriptAnalyzer
303
+ # /<modulefiles live here>
304
+ # and ".../out/PSScriptAnalyzer" is added to env:PSModulePath
305
+ #
306
+ #
307
+ $major = $PSVersionTable.PSVersion.Major
308
+ if ( $major -lt 5 ) {
309
+ # get the directory name of the destination, we need to change it
310
+ $versionDirectoryRoot = Split-Path $script :destinationDir
311
+ $testModulePath = Join-Path $versionDirectoryRoot $analyzerName
312
+ }
313
+ else {
314
+ $testModulePath = Join-Path " ${projectRoot} " - ChildPath out
315
+ }
284
316
$testResultsFile = " '$ ( Join-Path ${projectRoot} - childPath TestResults.xml) '"
285
317
$testScripts = " '${projectRoot} \Tests\Engine','${projectRoot} \Tests\Rules','${projectRoot} \Tests\Documentation'"
286
318
try {
319
+ if ( $major -lt 5 ) {
320
+ Rename-Item $script :destinationDir ${testModulePath}
321
+ }
287
322
$savedModulePath = $env: PSModulePath
288
323
$env: PSModulePath = " ${testModulePath} {0}${env: PSModulePath} " -f [System.IO.Path ]::PathSeparator
289
324
if ($ShowAll )
@@ -304,6 +339,9 @@ function Test-ScriptAnalyzer
304
339
}
305
340
finally {
306
341
$env: PSModulePath = $savedModulePath
342
+ if ( $major -lt 5 ) {
343
+ Rename-Item ${testModulePath} ${script :destinationDir}
344
+ }
307
345
}
308
346
}
309
347
}
0 commit comments