Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade from net452 to net462 for Windows PowerShell #1789

Merged
merged 8 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Engine/Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

<PropertyGroup>
<VersionPrefix>1.21.0</VersionPrefix>
<TargetFrameworks>netcoreapp3.1;net452</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer</AssemblyName>
<AssemblyVersion>1.21.0</AssemblyVersion>
<PackageId>Engine</PackageId>
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="System.ComponentModel.Composition" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'net462' ">
<DebugType>portable</DebugType>
</PropertyGroup>

Expand Down Expand Up @@ -70,15 +70,15 @@
<DefineConstants>$(DefineConstants);PSV7;CORECLR</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net452' AND '$(Configuration)' == 'PSV3Release' AND '$(Configuration)' != 'PSV4Release'">
<ItemGroup Condition="'$(TargetFramework)' == 'net462' AND '$(Configuration)' == 'PSV3Release' AND '$(Configuration)' != 'PSV4Release'">
<PackageReference Include="Microsoft.PowerShell.3.ReferenceAssemblies" Version="1.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net452' AND '$(Configuration)' == 'PSV4Release'">
<ItemGroup Condition="'$(TargetFramework)' == 'net462' AND '$(Configuration)' == 'PSV4Release'">
<PackageReference Include="Microsoft.PowerShell.4.ReferenceAssemblies" Version="1.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net452' AND '$(Configuration)' != 'PSV3Release'">
<ItemGroup Condition="'$(TargetFramework)' == 'net462' AND '$(Configuration)' != 'PSV3Release'">
<PackageReference Include="Microsoft.PowerShell.5.ReferenceAssemblies" Version="1.1.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Engine/FindAstPositionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<VersionPrefix>1.21.0</VersionPrefix>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<AssemblyVersion>1.21.0</AssemblyVersion>
</PropertyGroup>

Expand All @@ -16,7 +16,7 @@
<PackageReference Include="PowerShellStandard.Library" Version="3.0.0-preview-02" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="Microsoft.PowerShell.3.ReferenceAssemblies" Version="1.0.0" />
<PackageReference Include="Microsoft.Management.Infrastructure" Version="1.0.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion PSCompatibilityCollector/PSCompatibilityCollector.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions PSCompatibilityCollector/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ param(
$Configuration = 'Debug',

[Parameter()]
[ValidateSet('netstandard2.0', 'net452')]
[ValidateSet('netstandard2.0', 'net462')]
[string]
$Framework,

Expand All @@ -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
Expand All @@ -36,15 +36,15 @@ $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')
}

function Invoke-CrossCompatibilityModuleBuild
{
param(
[Parameter()]
[ValidateSet('netstandard2.0', 'net452')]
[ValidateSet('netstandard2.0', 'net462')]
[string]
$Framework = 'netstandard2.0',

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions Rules/Rules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<VersionPrefix>1.21.0</VersionPrefix>
<TargetFrameworks>netcoreapp3.1;net452</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules</AssemblyName>
<AssemblyVersion>1.21.0</AssemblyVersion>
<PackageId>Rules</PackageId>
Expand All @@ -22,12 +22,12 @@
<PackageReference Include="Pluralize.NET" Version="1.0.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Data.Entity.Design" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'net462' ">
<DebugType>portable</DebugType>
</PropertyGroup>

Expand Down
10 changes: 5 additions & 5 deletions Rules/UseCmdletCorrectly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public class UseCmdletCorrectly : IScriptRule
private static readonly ConcurrentDictionary<string, IReadOnlyList<string>> s_pkgMgmtMandatoryParameters =
new ConcurrentDictionary<string, IReadOnlyList<string>>(new Dictionary<string, IReadOnlyList<string>>
{
{ "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<string>() },
{ "Find-PackageProvider", Array.Empty<string>() },
{ "Get-Package", Array.Empty<string>() },
{ "Get-PackageProvider", Array.Empty<string>() },
{ "Get-PackageSource", Array.Empty<string>() },
{ "Import-PackageProvider", new string[] { "Name" } },
{ "Install-Package", new string[] { "Name" } },
{ "Install-PackageProvider", new string[] { "Name" } },
Expand Down
10 changes: 5 additions & 5 deletions Rules/UseUsingScopeModifierInNewRunspaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public override AstVisitAction VisitScriptBlockExpression(ScriptBlockExpressionA
return AstVisitAction.Continue;
}

HashSet<string> varsInLocalAssignments = FindVarsInAssignmentAsts(scriptBlockExpressionAst);
IReadOnlyCollection<string> varsInLocalAssignments = FindVarsInAssignmentAsts(scriptBlockExpressionAst);
if (varsInLocalAssignments != null)
{
AddAssignedVarsToSession(sessionName, varsInLocalAssignments);
Expand All @@ -205,7 +205,7 @@ public override AstVisitAction VisitScriptBlockExpression(ScriptBlockExpressionA
/// Example: `$foo = "foo"` ==> the VariableExpressionAst for $foo is returned
/// </summary>
/// <param name="ast"></param>
private static HashSet<string> FindVarsInAssignmentAsts(Ast ast)
private static IReadOnlyCollection<string> FindVarsInAssignmentAsts(Ast ast)
{
HashSet<string> variableDictionary =
new HashSet<string>();
Expand Down Expand Up @@ -264,7 +264,7 @@ private static bool IsAssignmentStatementAst(Ast ast)
/// <param name="ast"></param>
/// <param name="varsInAssignments"></param>
private static IEnumerable<VariableExpressionAst> FindNonAssignedNonUsingVarAsts(
Ast ast, HashSet<string> varsInAssignments)
Ast ast, IReadOnlyCollection<string> varsInAssignments)
{
// Find all variables that are not locally assigned, and don't have $using: scope modifier
foreach (VariableExpressionAst variable in ast.FindAll(IsNonUsingNonSpecialVariableExpressionAst, true))
Expand Down Expand Up @@ -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).
/// </summary>
/// <param name="sessionName"></param>
private HashSet<string> GetAssignedVarsInSession(string sessionName)
private IReadOnlyCollection<string> GetAssignedVarsInSession(string sessionName)
{
return _varsDeclaredPerSession[sessionName];
}
Expand All @@ -378,7 +378,7 @@ private HashSet<string> GetAssignedVarsInSession(string sessionName)
/// </summary>
/// <param name="sessionName"></param>
/// <param name="variablesToAdd"></param>
private void AddAssignedVarsToSession(string sessionName, HashSet<string> variablesToAdd)
private void AddAssignedVarsToSession(string sessionName, IReadOnlyCollection<string> variablesToAdd)
{
if (!_varsDeclaredPerSession.ContainsKey(sessionName))
{
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
6 changes: 3 additions & 3 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions tools/releaseBuild/signing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<file src="__INPATHROOT__\out\PSCompatibilityCollector\netstandard2.0\Microsoft.PowerShell.CrossCompatibility.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\netstandard2.0\Microsoft.PowerShell.CrossCompatibility.dll" />
<file src="__INPATHROOT__\out\PSCompatibilityCollector\netstandard2.0\Newtonsoft.Json.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\netstandard2.0\Newtonsoft.Json.dll" />
</job>
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Compatibility Analyzer net452 DLLs" approvers="vigarg;gstolt">
<file src="__INPATHROOT__\out\PSCompatibilityCollector\net452\Microsoft.PowerShell.CrossCompatibility.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\net452\Microsoft.PowerShell.CrossCompatibility.dll" />
<file src="__INPATHROOT__\out\PSCompatibilityCollector\net452\Newtonsoft.Json.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\net452\Newtonsoft.Json.dll" />
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Compatibility Analyzer net462 DLLs" approvers="vigarg;gstolt">
<file src="__INPATHROOT__\out\PSCompatibilityCollector\net462\Microsoft.PowerShell.CrossCompatibility.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\net462\Microsoft.PowerShell.CrossCompatibility.dll" />
<file src="__INPATHROOT__\out\PSCompatibilityCollector\net462\Newtonsoft.Json.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\net462\Newtonsoft.Json.dll" />
</job>
</SignConfigXML>