@@ -287,10 +287,38 @@ function Test-ScriptAnalyzer
287
287
param ( [Parameter ()][switch ]$InProcess , [switch ]$ShowAll )
288
288
289
289
END {
290
- $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
+ }
291
316
$testResultsFile = " '$ ( Join-Path ${projectRoot} - childPath TestResults.xml) '"
292
317
$testScripts = " '${projectRoot} \Tests\Engine','${projectRoot} \Tests\Rules','${projectRoot} \Tests\Documentation'"
293
318
try {
319
+ if ( $major -lt 5 ) {
320
+ Rename-Item $script :destinationDir ${testModulePath}
321
+ }
294
322
$savedModulePath = $env: PSModulePath
295
323
$env: PSModulePath = " ${testModulePath} {0}${env: PSModulePath} " -f [System.IO.Path ]::PathSeparator
296
324
if ($ShowAll )
@@ -311,6 +339,9 @@ function Test-ScriptAnalyzer
311
339
}
312
340
finally {
313
341
$env: PSModulePath = $savedModulePath
342
+ if ( $major -lt 5 ) {
343
+ Rename-Item ${testModulePath} ${script :destinationDir}
344
+ }
314
345
}
315
346
}
316
347
}
0 commit comments