Skip to content

Commit b030262

Browse files
authored
Upgrade from net452 to net462 for Windows PowerShell (#1789)
* upgrade from net452 to net461 for windows ps * fix casing and bug where psv7 wasn't used * use APIs available in net461 but not net452 * fix merge conflict error * empty
1 parent e6005a9 commit b030262

File tree

13 files changed

+39
-37
lines changed

13 files changed

+39
-37
lines changed

Engine/Engine.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
<PropertyGroup>
44
<VersionPrefix>1.21.0</VersionPrefix>
5-
<TargetFrameworks>netcoreapp3.1;net452</TargetFrameworks>
5+
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
66
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer</AssemblyName>
77
<AssemblyVersion>1.21.0</AssemblyVersion>
88
<PackageId>Engine</PackageId>
99
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
1010
<LangVersion>9.0</LangVersion>
1111
</PropertyGroup>
1212

13-
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
13+
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
1414
<Reference Include="System.ComponentModel.Composition" />
1515
</ItemGroup>
1616

17-
<PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
17+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net462' ">
1818
<DebugType>portable</DebugType>
1919
</PropertyGroup>
2020

@@ -70,15 +70,15 @@
7070
<DefineConstants>$(DefineConstants);PSV7;CORECLR</DefineConstants>
7171
</PropertyGroup>
7272

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

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

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

Engine/FindAstPositionVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public override AstVisitAction VisitUsingStatement(UsingStatementAst usingStatem
337337
}
338338
#endif
339339

340-
#if !(NET452 || PSV6) // NET452 includes V3,4,5
340+
#if !(NET462 || PSV7) // net462 includes V3,4,5
341341
public override AstVisitAction VisitPipelineChain(PipelineChainAst pipelineChainAst)
342342
{
343343
return Visit(pipelineChainAst);

PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Collection/PlatformInformationCollector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ private Architecture GetProcessArchitecture()
330330
return (Architecture)RuntimeInformation.ProcessArchitecture;
331331
#else
332332
// We assume .NET Framework must be on an Intel architecture
333-
// net452 does not reliably have the above API
333+
// net462 does not reliably have the above API
334334
return Environment.Is64BitProcess
335335
? Architecture.X64
336336
: Architecture.X86;
@@ -344,7 +344,7 @@ private Architecture GetOSArchitecture()
344344
return (Architecture)RuntimeInformation.OSArchitecture;
345345
#else
346346
// We assume .NET Framework must be on an Intel architecture
347-
// net452 does not reliably have the above API
347+
// net462 does not reliably have the above API
348348
return Environment.Is64BitOperatingSystem
349349
? Architecture.X64
350350
: Architecture.X86;

PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Microsoft.PowerShell.CrossCompatibility.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<VersionPrefix>1.21.0</VersionPrefix>
5-
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
5+
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
66
<AssemblyVersion>1.21.0</AssemblyVersion>
77
</PropertyGroup>
88

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

19-
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
19+
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
2020
<PackageReference Include="Microsoft.PowerShell.3.ReferenceAssemblies" Version="1.0.0" />
2121
<PackageReference Include="Microsoft.Management.Infrastructure" Version="1.0.0" />
2222
</ItemGroup>

PSCompatibilityCollector/PSCompatibilityCollector.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ if ($PSVersionTable.PSVersion.Major -ge 6)
88
}
99
else
1010
{
11-
Import-Module ([System.IO.Path]::Combine($PSScriptRoot, 'net452', 'Microsoft.PowerShell.CrossCompatibility.dll')) -Force
11+
Import-Module ([System.IO.Path]::Combine($PSScriptRoot, 'net462', 'Microsoft.PowerShell.CrossCompatibility.dll')) -Force
1212
}

PSCompatibilityCollector/build.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ param(
88
$Configuration = 'Debug',
99

1010
[Parameter()]
11-
[ValidateSet('netstandard2.0', 'net452')]
11+
[ValidateSet('netstandard2.0', 'net462')]
1212
[string]
1313
$Framework,
1414

@@ -24,7 +24,7 @@ $ErrorActionPreference = 'Stop'
2424
if ($IsWindows -eq $false) {
2525
$script:TargetFrameworks = 'netstandard2.0'
2626
} else {
27-
$script:TargetFrameworks = 'netstandard2.0','net452'
27+
$script:TargetFrameworks = 'netstandard2.0','net462'
2828
}
2929

3030
$script:ModuleName = Split-Path $PSScriptRoot -Leaf
@@ -36,15 +36,15 @@ $script:BinModDir = [System.IO.Path]::Combine($PSScriptRoot, 'out', "$script:Mod
3636
$script:BinModSrcDir = Join-Path $PSScriptRoot 'Microsoft.PowerShell.CrossCompatibility'
3737

3838
$script:PublishDlls = @{
39-
'net452' = @('Microsoft.PowerShell.CrossCompatibility.dll', 'Microsoft.PowerShell.CrossCompatibility.pdb', 'Newtonsoft.Json.dll')
39+
'net462' = @('Microsoft.PowerShell.CrossCompatibility.dll', 'Microsoft.PowerShell.CrossCompatibility.pdb', 'Newtonsoft.Json.dll')
4040
'netstandard2.0' = @('Microsoft.PowerShell.CrossCompatibility.dll', 'Microsoft.PowerShell.CrossCompatibility.pdb', 'Newtonsoft.Json.dll')
4141
}
4242

4343
function Invoke-CrossCompatibilityModuleBuild
4444
{
4545
param(
4646
[Parameter()]
47-
[ValidateSet('netstandard2.0', 'net452')]
47+
[ValidateSet('netstandard2.0', 'net462')]
4848
[string]
4949
$Framework = 'netstandard2.0',
5050

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ To install **PSScriptAnalyzer** from source code:
7171

7272
- [.NET Core 3.1.102 SDK](https://www.microsoft.com/net/download/dotnet-core/3.1#sdk-3.1.102) or
7373
newer patch release
74+
* 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.
75+
* Optionally but recommended for development: [Visual Studio 2017/2019](https://www.visualstudio.com/downloads)
7476
- [Pester v5 PowerShell module, available on PowerShell Gallery](https://github.com/pester/Pester)
7577
- [PlatyPS PowerShell module, available on PowerShell Gallery](https://github.com/PowerShell/platyPS/releases)
76-
- Optionally but recommended for development: [Visual Studio 2017/2019](https://www.visualstudio.com/downloads/)
78+
- Optionally but recommended for development: [Visual Studio](https://www.visualstudio.com/downloads)
7779

7880
### Steps
7981

Rules/Rules.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<VersionPrefix>1.21.0</VersionPrefix>
5-
<TargetFrameworks>netcoreapp3.1;net452</TargetFrameworks>
5+
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
66
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules</AssemblyName>
77
<AssemblyVersion>1.21.0</AssemblyVersion>
88
<PackageId>Rules</PackageId>
@@ -22,12 +22,12 @@
2222
<PackageReference Include="Pluralize.NET" Version="1.0.2" />
2323
</ItemGroup>
2424

25-
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
25+
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
2626
<Reference Include="System.ComponentModel.Composition" />
2727
<Reference Include="System.Data.Entity.Design" />
2828
</ItemGroup>
2929

30-
<PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
30+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net462' ">
3131
<DebugType>portable</DebugType>
3232
</PropertyGroup>
3333

Rules/UseCmdletCorrectly.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public class UseCmdletCorrectly : IScriptRule
2929
private static readonly ConcurrentDictionary<string, IReadOnlyList<string>> s_pkgMgmtMandatoryParameters =
3030
new ConcurrentDictionary<string, IReadOnlyList<string>>(new Dictionary<string, IReadOnlyList<string>>
3131
{
32-
{ "Find-Package", new string[0] },
33-
{ "Find-PackageProvider", new string[0] },
34-
{ "Get-Package", new string[0] },
35-
{ "Get-PackageProvider", new string[0] },
36-
{ "Get-PackageSource", new string[0] },
32+
{ "Find-Package", Array.Empty<string>() },
33+
{ "Find-PackageProvider", Array.Empty<string>() },
34+
{ "Get-Package", Array.Empty<string>() },
35+
{ "Get-PackageProvider", Array.Empty<string>() },
36+
{ "Get-PackageSource", Array.Empty<string>() },
3737
{ "Import-PackageProvider", new string[] { "Name" } },
3838
{ "Install-Package", new string[] { "Name" } },
3939
{ "Install-PackageProvider", new string[] { "Name" } },

Rules/UseUsingScopeModifierInNewRunspaces.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public override AstVisitAction VisitScriptBlockExpression(ScriptBlockExpressionA
183183
return AstVisitAction.Continue;
184184
}
185185

186-
HashSet<string> varsInLocalAssignments = FindVarsInAssignmentAsts(scriptBlockExpressionAst);
186+
IReadOnlyCollection<string> varsInLocalAssignments = FindVarsInAssignmentAsts(scriptBlockExpressionAst);
187187
if (varsInLocalAssignments != null)
188188
{
189189
AddAssignedVarsToSession(sessionName, varsInLocalAssignments);
@@ -205,7 +205,7 @@ public override AstVisitAction VisitScriptBlockExpression(ScriptBlockExpressionA
205205
/// Example: `$foo = "foo"` ==> the VariableExpressionAst for $foo is returned
206206
/// </summary>
207207
/// <param name="ast"></param>
208-
private static HashSet<string> FindVarsInAssignmentAsts(Ast ast)
208+
private static IReadOnlyCollection<string> FindVarsInAssignmentAsts(Ast ast)
209209
{
210210
HashSet<string> variableDictionary =
211211
new HashSet<string>();
@@ -264,7 +264,7 @@ private static bool IsAssignmentStatementAst(Ast ast)
264264
/// <param name="ast"></param>
265265
/// <param name="varsInAssignments"></param>
266266
private static IEnumerable<VariableExpressionAst> FindNonAssignedNonUsingVarAsts(
267-
Ast ast, HashSet<string> varsInAssignments)
267+
Ast ast, IReadOnlyCollection<string> varsInAssignments)
268268
{
269269
// Find all variables that are not locally assigned, and don't have $using: scope modifier
270270
foreach (VariableExpressionAst variable in ast.FindAll(IsNonUsingNonSpecialVariableExpressionAst, true))
@@ -368,7 +368,7 @@ private static bool TryGetSessionNameFromInvokeCommand(CommandAst invokeCommandA
368368
/// GetAssignedVarsInSession: Retrieves all previously declared vars for a given session (as in Invoke-Command -Session $session).
369369
/// </summary>
370370
/// <param name="sessionName"></param>
371-
private HashSet<string> GetAssignedVarsInSession(string sessionName)
371+
private IReadOnlyCollection<string> GetAssignedVarsInSession(string sessionName)
372372
{
373373
return _varsDeclaredPerSession[sessionName];
374374
}
@@ -378,7 +378,7 @@ private HashSet<string> GetAssignedVarsInSession(string sessionName)
378378
/// </summary>
379379
/// <param name="sessionName"></param>
380380
/// <param name="variablesToAdd"></param>
381-
private void AddAssignedVarsToSession(string sessionName, HashSet<string> variablesToAdd)
381+
private void AddAssignedVarsToSession(string sessionName, IReadOnlyCollection<string> variablesToAdd)
382382
{
383383
if (!_varsDeclaredPerSession.ContainsKey(sessionName))
384384
{

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ build_script:
3030
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 3
3131
}
3232
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion "$env:PSVersion"
33-
./PSCompatibilityCollector/build.ps1 -Configuration "$env:BuildConfiguration" -Framework 'net452'
33+
./PSCompatibilityCollector/build.ps1 -Configuration "$env:BuildConfiguration" -Framework 'net462'
3434
}
3535
- pwsh: |
3636
if ($env:PowerShellEdition -eq 'PowerShellCore') {

build.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ function Start-ScriptAnalyzerBuild
201201
Set-Variable -Name profilesCopied -Value $true -Scope 1
202202
}
203203

204-
$framework = 'net452'
204+
$framework = 'net462'
205205
if ($PSVersion -eq 7) {
206206
$framework = 'netcoreapp3.1'
207207
}
208208

209209
# build the appropriate assembly
210-
if ($PSVersion -match "[34]" -and $Framework -ne "net452")
210+
if ($PSVersion -match "[34]" -and $Framework -ne "net462")
211211
{
212212
throw ("ScriptAnalyzer for PS version '{0}' is not applicable to {1} framework" -f $PSVersion,$Framework)
213213
}
@@ -322,7 +322,7 @@ function Start-ScriptAnalyzerBuild
322322
else {
323323
"$projectRoot\Rules\bin\${buildConfiguration}\${framework}"
324324
}
325-
if ($framework -eq 'net452') {
325+
if ($framework -eq 'net462') {
326326
$nsoft = Join-Path $rulesProjectOutputDir 'Newtonsoft.Json.dll'
327327
Copy-Item -path $nsoft -Destination $destinationDirBinaries
328328
}

tools/releaseBuild/signing.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
<file src="__INPATHROOT__\out\PSCompatibilityCollector\netstandard2.0\Microsoft.PowerShell.CrossCompatibility.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\netstandard2.0\Microsoft.PowerShell.CrossCompatibility.dll" />
4545
<file src="__INPATHROOT__\out\PSCompatibilityCollector\netstandard2.0\Newtonsoft.Json.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\netstandard2.0\Newtonsoft.Json.dll" />
4646
</job>
47-
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Compatibility Analyzer net452 DLLs" approvers="vigarg;gstolt">
48-
<file src="__INPATHROOT__\out\PSCompatibilityCollector\net452\Microsoft.PowerShell.CrossCompatibility.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\net452\Microsoft.PowerShell.CrossCompatibility.dll" />
49-
<file src="__INPATHROOT__\out\PSCompatibilityCollector\net452\Newtonsoft.Json.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\net452\Newtonsoft.Json.dll" />
47+
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Compatibility Analyzer net462 DLLs" approvers="vigarg;gstolt">
48+
<file src="__INPATHROOT__\out\PSCompatibilityCollector\net462\Microsoft.PowerShell.CrossCompatibility.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\net462\Microsoft.PowerShell.CrossCompatibility.dll" />
49+
<file src="__INPATHROOT__\out\PSCompatibilityCollector\net462\Newtonsoft.Json.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\net462\Newtonsoft.Json.dll" />
5050
</job>
5151
</SignConfigXML>

0 commit comments

Comments
 (0)