@@ -7,8 +7,7 @@ $analyzerName = "PSScriptAnalyzer"
7
7
8
8
function Get-AnalyzerVersion
9
9
{
10
- $csprojPath = [io.path ]::Combine($projectRoot , " Engine" , " Engine.csproj" )
11
- $xml = [xml ](Get-Content " ${csprojPath} " )
10
+ [xml ]$xml = Get-Content $ ([io.path ]::Combine($projectRoot , " Engine" , " Engine.csproj" ))
12
11
$xml.SelectSingleNode (" .//VersionPrefix" )." #text"
13
12
}
14
13
@@ -29,61 +28,6 @@ function Publish-File
29
28
}
30
29
}
31
30
32
- # attempt to get the users module directory
33
- function Get-UserModulePath
34
- {
35
- if ( $IsCoreCLR -and -not $IsWindows )
36
- {
37
- $platformType = " System.Management.Automation.Platform" -as [Type ]
38
- if ( $platformType ) {
39
- ${platformType} ::SelectProductNameForDirectory(" USER_MODULES" )
40
- }
41
- else {
42
- throw " Could not determine users module path"
43
- }
44
- }
45
- else {
46
- " ${HOME} /Documents/WindowsPowerShell/Modules"
47
- }
48
- }
49
-
50
-
51
- function Uninstall-ScriptAnalyzer
52
- {
53
- [CmdletBinding (SupportsShouldProcess )]
54
- param ( $ModulePath = $ (Join-Path - Path (Get-UserModulePath ) - ChildPath ${analyzerName} ) )
55
- END {
56
- if ( $PSCmdlet.ShouldProcess (" $modulePath " ) ) {
57
- Remove-Item - Recurse - Path " $ModulePath " - Force
58
- }
59
- }
60
- }
61
-
62
- # install script analyzer, by default into the users module path
63
- function Install-ScriptAnalyzer
64
- {
65
- [CmdletBinding (SupportsShouldProcess )]
66
- param ( $ModulePath = $ (Join-Path - Path (Get-UserModulePath ) - ChildPath ${analyzerName} ) )
67
- END {
68
- if ( $PSCmdlet.ShouldProcess (" $modulePath " ) ) {
69
- Copy-Item - Recurse - Path " $script :destinationDir " - Destination " $ModulePath \." - Force
70
- }
71
- }
72
- }
73
-
74
- # if script analyzer is installed, remove it
75
- function Uninstall-ScriptAnalyzer
76
- {
77
- [CmdletBinding (SupportsShouldProcess )]
78
- param ( $ModulePath = $ (Join-Path - Path (Get-UserModulePath ) - ChildPath ${analyzerName} ) )
79
- END {
80
- if ((Test-Path $ModulePath ) -and (Get-Item $ModulePath ).PSIsContainer )
81
- {
82
- Remove-Item - Force - Recurse $ModulePath
83
- }
84
- }
85
- }
86
-
87
31
# Clean up the build location
88
32
function Remove-Build
89
33
{
@@ -157,9 +101,6 @@ function Start-ScriptAnalyzerBuild
157
101
158
102
BEGIN {
159
103
# don't allow the build to be started unless we have the proper Cli version
160
- # this will not actually install dotnet if it's already present, but it will
161
- # install the proper version
162
- Install-Dotnet
163
104
if ( -not (Test-SuitableDotnet ) ) {
164
105
$requiredVersion = $script :wantedVersion
165
106
$foundVersion = Get-InstalledCLIVersion
@@ -431,49 +372,6 @@ function Get-TestFailures
431
372
$results.SelectNodes (" .//test-case[@result='Failure']" )
432
373
}
433
374
434
- # BOOTSTRAPPING CODE FOR INSTALLING DOTNET
435
- # install dotnet cli tools based on the version mentioned in global.json
436
- function Install-Dotnet
437
- {
438
- [CmdletBinding (SupportsShouldProcess = $true )]
439
- param (
440
- [Parameter ()][Switch ]$Force ,
441
- [Parameter ()]$version = $ ( Get-GlobalJsonSdkVersion - Raw )
442
- )
443
-
444
- if ( Test-DotnetInstallation - requestedversion $version ) {
445
- if ( $Force ) {
446
- Write-Verbose - Verbose " Installing again"
447
- }
448
- else {
449
- return
450
- }
451
- }
452
-
453
- try {
454
- Push-Location $PSScriptRoot
455
- $installScriptPath = Receive-DotnetInstallScript
456
- $installScriptName = [System.IO.Path ]::GetFileName($installScriptPath )
457
- If ( $PSCmdlet.ShouldProcess (" $installScriptName for $version " )) {
458
- & " ${installScriptPath} " - c release - version $version - SkipNonVersionedFiles
459
- }
460
- # this may be the first time that dotnet has been installed,
461
- # set up the executable variable
462
- if ( -not $script :DotnetExe ) {
463
- $script :DotnetExe = Get-DotnetExe
464
- }
465
- }
466
- catch {
467
- throw $_
468
- }
469
- finally {
470
- if ( Test-Path $installScriptPath ) {
471
- Remove-Item $installScriptPath
472
- }
473
- Pop-Location
474
- }
475
- }
476
-
477
375
function Get-GlobalJsonSdkVersion {
478
376
param ( [switch ]$Raw )
479
377
$json = Get-Content - raw (Join-Path $PSScriptRoot global.json) | ConvertFrom-Json
@@ -612,68 +510,6 @@ function Get-InstalledCLIVersion {
612
510
return (ConvertTo-PortableVersion $installedVersions )
613
511
}
614
512
615
- function Test-DotnetInstallation
616
- {
617
- param (
618
- $requestedVersion = $script :wantedVersion ,
619
- $installedVersions = $ ( Get-InstalledCLIVersion )
620
- )
621
- return (Test-SuitableDotnet - availableVersions $installedVersions - requiredVersion $requestedVersion )
622
- }
623
-
624
- function Receive-File {
625
- param ( [Parameter (Mandatory , Position = 0 )]$uri )
626
-
627
- # enable Tls12 for the request
628
- # -SslProtocol parameter for Invoke-WebRequest wasn't in PSv3
629
- $securityProtocol = [System.Net.ServicePointManager ]::SecurityProtocol
630
- $tls12 = [System.Net.SecurityProtocolType ]::Tls12
631
- try {
632
- if ( ([System.Net.ServicePointManager ]::SecurityProtocol -band $tls12 ) -eq 0 ) {
633
- [System.Net.ServicePointManager ]::SecurityProtocol = [System.Net.ServicePointManager ]::SecurityProtocol -bor $tls12
634
- }
635
- $null = Invoke-WebRequest - Uri ${uri} - OutFile " ${installScriptName} "
636
- }
637
- finally {
638
- [System.Net.ServicePointManager ]::SecurityProtocol = $securityProtocol
639
- }
640
- if ( (Test-Path Variable:IsWindows) -and -not $IsWindows ) {
641
- chmod + x $installScriptName
642
- }
643
- $installScript = Get-Item $installScriptName - ErrorAction Stop
644
- if ( -not $installScript ) {
645
- throw " Download failure of ${uri} "
646
- }
647
- return $installScript
648
- }
649
-
650
- function Receive-DotnetInstallScript
651
- {
652
- # param '$platform' is a hook to enable forcing download of a specific
653
- # install script, generally it should not be used except in testing.
654
- param ( $platform = " " )
655
-
656
- # if $platform has been set, it has priority
657
- # if it's not set to Windows or NonWindows, it will be ignored
658
- if ( $platform -eq " Windows" ) {
659
- $installScriptName = " dotnet-install.ps1"
660
- }
661
- elseif ( $platform -eq " NonWindows" ) {
662
- $installScriptName = " dotnet-install.sh"
663
- }
664
- elseif ( ((Test-Path Variable:IsWindows) -and -not $IsWindows ) ) {
665
- # if the variable IsWindows exists and it is set to false
666
- $installScriptName = " dotnet-install.sh"
667
- }
668
- else { # the default case - we're running on a Windows system
669
- $installScriptName = " dotnet-install.ps1"
670
- }
671
- $uri = " https://dot.net/v1/${installScriptName} "
672
-
673
- $installScript = Receive-File - Uri $uri
674
- return $installScript.FullName
675
- }
676
-
677
513
function Get-DotnetExe
678
514
{
679
515
param ( $version = $script :wantedVersion )
@@ -730,7 +566,7 @@ try {
730
566
$script :DotnetExe = Get-DotnetExe
731
567
}
732
568
catch {
733
- Write-Warning " Could not find dotnet executable "
569
+ Write-Warning " The dotnet CLI was not found, please install it: https://aka.ms/dotnet-cli "
734
570
}
735
571
736
572
# Copies the built PSCompatibilityCollector module to the output destination for PSSA
@@ -780,44 +616,11 @@ function Copy-CrossCompatibilityModule
780
616
}
781
617
}
782
618
783
- # copy the manifest into the module if is present
784
- function Copy-Manifest
785
- {
786
- param ( [switch ]$signed )
787
- if ( $signed ) {
788
- $buildRoot = " signed"
789
- }
790
- else {
791
- $buildRoot = " out"
792
- }
793
- $analyzerVersion = Get-AnalyzerVersion
794
- # location where analyzer goes
795
- # debugging
796
- (Get-ChildItem - File - Recurse)| ForEach-Object {Write-Verbose - Verbose - Message $_ }
797
- $modBaseDir = [io.path ]::Combine($projectRoot , ${buildRoot} , " ${analyzerName} " , $analyzerVersion )
798
- # copy the manifest files
799
- Push-Location $buildRoot
800
- if ( Test-Path _manifest ) {
801
- Copy-Item - Recurse - Path _manifest - Destination $modBaseDir - Verbose
802
- }
803
- else {
804
- Write-Warning - Message " _manifest not found in $PWD "
805
- }
806
- Pop-Location
807
- }
808
-
809
619
# creates the nuget package which can be used for publishing to the gallery
810
620
function Start-CreatePackage
811
621
{
812
- [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSUseCompatibleCommands' , ' ' )]
813
- param ( [switch ]$signed )
814
622
try {
815
- if ( $signed ) {
816
- $buildRoot = " signed"
817
- }
818
- else {
819
- $buildRoot = " out"
820
- }
623
+ $buildRoot = " out"
821
624
$repoName = [guid ]::NewGuid().ToString()
822
625
$nupkgDir = Join-Path $PSScriptRoot $buildRoot
823
626
$null = Register-PSRepository - Name $repoName - InstallationPolicy Trusted - SourceLocation $nupkgDir
0 commit comments