diff --git a/Engine/Engine.csproj b/Engine/Engine.csproj index b7dfc14ce..10ebf1222 100644 --- a/Engine/Engine.csproj +++ b/Engine/Engine.csproj @@ -2,7 +2,7 @@ 1.21.0 - netcoreapp3.1;net452 + netcoreapp3.1;net462 Microsoft.Windows.PowerShell.ScriptAnalyzer 1.21.0 Engine @@ -10,11 +10,11 @@ 9.0 - + - + portable @@ -70,15 +70,15 @@ $(DefineConstants);PSV7;CORECLR - + - + - + diff --git a/Engine/FindAstPositionVisitor.cs b/Engine/FindAstPositionVisitor.cs index 5816f7e59..05532c456 100644 --- a/Engine/FindAstPositionVisitor.cs +++ b/Engine/FindAstPositionVisitor.cs @@ -337,7 +337,7 @@ public override AstVisitAction VisitUsingStatement(UsingStatementAst usingStatem } #endif -#if !(NET452 || PSV6) // NET452 includes V3,4,5 +#if !(NET462 || PSV7) // net462 includes V3,4,5 public override AstVisitAction VisitPipelineChain(PipelineChainAst pipelineChainAst) { return Visit(pipelineChainAst); diff --git a/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PlatformInformationCollector.cs b/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PlatformInformationCollector.cs index dfd62b806..9a7eab952 100644 --- a/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PlatformInformationCollector.cs +++ b/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PlatformInformationCollector.cs @@ -330,7 +330,7 @@ private Architecture GetProcessArchitecture() return (Architecture)RuntimeInformation.ProcessArchitecture; #else // We assume .NET Framework must be on an Intel architecture - // net452 does not reliably have the above API + // net462 does not reliably have the above API return Environment.Is64BitProcess ? Architecture.X64 : Architecture.X86; @@ -344,7 +344,7 @@ private Architecture GetOSArchitecture() return (Architecture)RuntimeInformation.OSArchitecture; #else // We assume .NET Framework must be on an Intel architecture - // net452 does not reliably have the above API + // net462 does not reliably have the above API return Environment.Is64BitOperatingSystem ? Architecture.X64 : Architecture.X86; diff --git a/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Microsoft.PowerShell.CrossCompatibility.csproj b/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Microsoft.PowerShell.CrossCompatibility.csproj index ea03d2c85..45042db64 100644 --- a/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Microsoft.PowerShell.CrossCompatibility.csproj +++ b/PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Microsoft.PowerShell.CrossCompatibility.csproj @@ -2,7 +2,7 @@ 1.21.0 - netstandard2.0;net452 + netstandard2.0;net462 1.21.0 @@ -16,7 +16,7 @@ - + diff --git a/PSCompatibilityCollector/PSCompatibilityCollector.psm1 b/PSCompatibilityCollector/PSCompatibilityCollector.psm1 index aea680da4..0e3f6a8e4 100644 --- a/PSCompatibilityCollector/PSCompatibilityCollector.psm1 +++ b/PSCompatibilityCollector/PSCompatibilityCollector.psm1 @@ -8,5 +8,5 @@ if ($PSVersionTable.PSVersion.Major -ge 6) } else { - Import-Module ([System.IO.Path]::Combine($PSScriptRoot, 'net452', 'Microsoft.PowerShell.CrossCompatibility.dll')) -Force + Import-Module ([System.IO.Path]::Combine($PSScriptRoot, 'net462', 'Microsoft.PowerShell.CrossCompatibility.dll')) -Force } diff --git a/PSCompatibilityCollector/build.ps1 b/PSCompatibilityCollector/build.ps1 index ec028ee08..0d1b47958 100644 --- a/PSCompatibilityCollector/build.ps1 +++ b/PSCompatibilityCollector/build.ps1 @@ -8,7 +8,7 @@ param( $Configuration = 'Debug', [Parameter()] - [ValidateSet('netstandard2.0', 'net452')] + [ValidateSet('netstandard2.0', 'net462')] [string] $Framework, @@ -24,7 +24,7 @@ $ErrorActionPreference = 'Stop' if ($IsWindows -eq $false) { $script:TargetFrameworks = 'netstandard2.0' } else { - $script:TargetFrameworks = 'netstandard2.0','net452' + $script:TargetFrameworks = 'netstandard2.0','net462' } $script:ModuleName = Split-Path $PSScriptRoot -Leaf @@ -36,7 +36,7 @@ $script:BinModDir = [System.IO.Path]::Combine($PSScriptRoot, 'out', "$script:Mod $script:BinModSrcDir = Join-Path $PSScriptRoot 'Microsoft.PowerShell.CrossCompatibility' $script:PublishDlls = @{ - 'net452' = @('Microsoft.PowerShell.CrossCompatibility.dll', 'Microsoft.PowerShell.CrossCompatibility.pdb', 'Newtonsoft.Json.dll') + 'net462' = @('Microsoft.PowerShell.CrossCompatibility.dll', 'Microsoft.PowerShell.CrossCompatibility.pdb', 'Newtonsoft.Json.dll') 'netstandard2.0' = @('Microsoft.PowerShell.CrossCompatibility.dll', 'Microsoft.PowerShell.CrossCompatibility.pdb', 'Newtonsoft.Json.dll') } @@ -44,7 +44,7 @@ function Invoke-CrossCompatibilityModuleBuild { param( [Parameter()] - [ValidateSet('netstandard2.0', 'net452')] + [ValidateSet('netstandard2.0', 'net462')] [string] $Framework = 'netstandard2.0', diff --git a/README.md b/README.md index 1308dff86..0bee936a2 100644 --- a/README.md +++ b/README.md @@ -71,9 +71,11 @@ To install **PSScriptAnalyzer** from source code: - [.NET Core 3.1.102 SDK](https://www.microsoft.com/net/download/dotnet-core/3.1#sdk-3.1.102) or newer patch release +* If building for Windows PowerShell versions, then the .NET Framework 4.6.2 [targeting pack](https://dotnet.microsoft.com/en-us/download/dotnet-framework/net462) (also referred to as developer/targeting pack) need to be installed. This is only possible on Windows. +* Optionally but recommended for development: [Visual Studio 2017/2019](https://www.visualstudio.com/downloads) - [Pester v5 PowerShell module, available on PowerShell Gallery](https://github.com/pester/Pester) - [PlatyPS PowerShell module, available on PowerShell Gallery](https://github.com/PowerShell/platyPS/releases) -- Optionally but recommended for development: [Visual Studio 2017/2019](https://www.visualstudio.com/downloads/) +- Optionally but recommended for development: [Visual Studio](https://www.visualstudio.com/downloads) ### Steps diff --git a/Rules/Rules.csproj b/Rules/Rules.csproj index 7a34e49c9..d6049acd6 100644 --- a/Rules/Rules.csproj +++ b/Rules/Rules.csproj @@ -2,7 +2,7 @@ 1.21.0 - netcoreapp3.1;net452 + netcoreapp3.1;net462 Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules 1.21.0 Rules @@ -22,12 +22,12 @@ - + - + portable diff --git a/Rules/UseCmdletCorrectly.cs b/Rules/UseCmdletCorrectly.cs index a0d08e2c1..0239d95fc 100644 --- a/Rules/UseCmdletCorrectly.cs +++ b/Rules/UseCmdletCorrectly.cs @@ -29,11 +29,11 @@ public class UseCmdletCorrectly : IScriptRule private static readonly ConcurrentDictionary> s_pkgMgmtMandatoryParameters = new ConcurrentDictionary>(new Dictionary> { - { "Find-Package", new string[0] }, - { "Find-PackageProvider", new string[0] }, - { "Get-Package", new string[0] }, - { "Get-PackageProvider", new string[0] }, - { "Get-PackageSource", new string[0] }, + { "Find-Package", Array.Empty() }, + { "Find-PackageProvider", Array.Empty() }, + { "Get-Package", Array.Empty() }, + { "Get-PackageProvider", Array.Empty() }, + { "Get-PackageSource", Array.Empty() }, { "Import-PackageProvider", new string[] { "Name" } }, { "Install-Package", new string[] { "Name" } }, { "Install-PackageProvider", new string[] { "Name" } }, diff --git a/Rules/UseUsingScopeModifierInNewRunspaces.cs b/Rules/UseUsingScopeModifierInNewRunspaces.cs index 6d665e989..a435c1d31 100644 --- a/Rules/UseUsingScopeModifierInNewRunspaces.cs +++ b/Rules/UseUsingScopeModifierInNewRunspaces.cs @@ -183,7 +183,7 @@ public override AstVisitAction VisitScriptBlockExpression(ScriptBlockExpressionA return AstVisitAction.Continue; } - HashSet varsInLocalAssignments = FindVarsInAssignmentAsts(scriptBlockExpressionAst); + IReadOnlyCollection varsInLocalAssignments = FindVarsInAssignmentAsts(scriptBlockExpressionAst); if (varsInLocalAssignments != null) { AddAssignedVarsToSession(sessionName, varsInLocalAssignments); @@ -205,7 +205,7 @@ public override AstVisitAction VisitScriptBlockExpression(ScriptBlockExpressionA /// Example: `$foo = "foo"` ==> the VariableExpressionAst for $foo is returned /// /// - private static HashSet FindVarsInAssignmentAsts(Ast ast) + private static IReadOnlyCollection FindVarsInAssignmentAsts(Ast ast) { HashSet variableDictionary = new HashSet(); @@ -264,7 +264,7 @@ private static bool IsAssignmentStatementAst(Ast ast) /// /// private static IEnumerable FindNonAssignedNonUsingVarAsts( - Ast ast, HashSet varsInAssignments) + Ast ast, IReadOnlyCollection varsInAssignments) { // Find all variables that are not locally assigned, and don't have $using: scope modifier foreach (VariableExpressionAst variable in ast.FindAll(IsNonUsingNonSpecialVariableExpressionAst, true)) @@ -368,7 +368,7 @@ private static bool TryGetSessionNameFromInvokeCommand(CommandAst invokeCommandA /// GetAssignedVarsInSession: Retrieves all previously declared vars for a given session (as in Invoke-Command -Session $session). /// /// - private HashSet GetAssignedVarsInSession(string sessionName) + private IReadOnlyCollection GetAssignedVarsInSession(string sessionName) { return _varsDeclaredPerSession[sessionName]; } @@ -378,7 +378,7 @@ private HashSet GetAssignedVarsInSession(string sessionName) /// /// /// - private void AddAssignedVarsToSession(string sessionName, HashSet variablesToAdd) + private void AddAssignedVarsToSession(string sessionName, IReadOnlyCollection variablesToAdd) { if (!_varsDeclaredPerSession.ContainsKey(sessionName)) { diff --git a/appveyor.yml b/appveyor.yml index 84f29a49f..e311eaa3a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,7 +30,7 @@ build_script: ./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 3 } ./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion "$env:PSVersion" - ./PSCompatibilityCollector/build.ps1 -Configuration "$env:BuildConfiguration" -Framework 'net452' + ./PSCompatibilityCollector/build.ps1 -Configuration "$env:BuildConfiguration" -Framework 'net462' } - pwsh: | if ($env:PowerShellEdition -eq 'PowerShellCore') { diff --git a/build.psm1 b/build.psm1 index 4ff8aac21..d6274ec5f 100644 --- a/build.psm1 +++ b/build.psm1 @@ -201,13 +201,13 @@ function Start-ScriptAnalyzerBuild Set-Variable -Name profilesCopied -Value $true -Scope 1 } - $framework = 'net452' + $framework = 'net462' if ($PSVersion -eq 7) { $framework = 'netcoreapp3.1' } # build the appropriate assembly - if ($PSVersion -match "[34]" -and $Framework -ne "net452") + if ($PSVersion -match "[34]" -and $Framework -ne "net462") { throw ("ScriptAnalyzer for PS version '{0}' is not applicable to {1} framework" -f $PSVersion,$Framework) } @@ -322,7 +322,7 @@ function Start-ScriptAnalyzerBuild else { "$projectRoot\Rules\bin\${buildConfiguration}\${framework}" } - if ($framework -eq 'net452') { + if ($framework -eq 'net462') { $nsoft = Join-Path $rulesProjectOutputDir 'Newtonsoft.Json.dll' Copy-Item -path $nsoft -Destination $destinationDirBinaries } diff --git a/tools/releaseBuild/signing.xml b/tools/releaseBuild/signing.xml index 25c44ff89..f2fc1c3ee 100644 --- a/tools/releaseBuild/signing.xml +++ b/tools/releaseBuild/signing.xml @@ -44,8 +44,8 @@ - - - + + +