Skip to content

Commit d3cd1f7

Browse files
Changes to build analyzer for PS7 and PS6 and ship in separate directories and bump version to 1.19.0 (#1425)
* Changes to break up coreclr build into PS6 and PS7 Since there are language changes in ps7, it seemed reasonable that distinct rules would be created to support these, which are not going to be in ps6 * move docker file changes from buildfeb2020 branch * use final version of 7 sdk * back to sdk 3.1.101 * back off to 3.1.101 * Bring version up to 1.19.0 * bump minimum ps6 to 6.2.4 * use downlevel newtonsoft library for PS6 * remove commented code in dockerfile * Address @bergmeister's comments * Move to SMA reference * Ensure SafeDirectoryCatalogue is not compiled in netcoreapp3.1 Co-authored-by: Robert Holt <[email protected]>
1 parent 791ee64 commit d3cd1f7

11 files changed

+127
-73
lines changed

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"search.exclude": {
99
"**/node_modules": true,
1010
"**/bower_components": true,
11-
"/PSCompatibilityAnalyzer/profiles": true,
12-
"/PSCompatibilityAnalyzer/optional_profiles": true
11+
"/PSCompatibilityCollector/profiles": true,
12+
"/PSCompatibilityCollector/optional_profiles": true
1313
}
1414
}

Engine/Engine.csproj

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>1.18.3</VersionPrefix>
5-
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
4+
<VersionPrefix>1.19.0</VersionPrefix>
5+
<TargetFrameworks>netcoreapp3.1;netstandard2.0;net452</TargetFrameworks>
66
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer</AssemblyName>
77
<PackageId>Engine</PackageId>
88
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
@@ -20,7 +20,7 @@
2020
<DefineConstants>$(DefineConstants);CORECLR</DefineConstants>
2121
</PropertyGroup>
2222

23-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
23+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netcoreapp3.1' ">
2424
<Compile Remove="SafeDirectoryCatalog.cs" />
2525
</ItemGroup>
2626

@@ -61,7 +61,29 @@
6161
</EmbeddedResource>
6262
</ItemGroup>
6363

64-
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
64+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Debug'">
65+
<PackageReference Include="System.Management.Automation" Version="7.0.0" />
66+
</ItemGroup>
67+
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Debug'">
68+
<DefineConstants>$(DefineConstants);PSV7;CORECLR</DefineConstants>
69+
</PropertyGroup>
70+
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Debug'">
71+
<DefineConstants>$(DefineConstants);PSV6;CORECLR</DefineConstants>
72+
</PropertyGroup>
73+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Debug'">
74+
<PackageReference Include="System.Management.Automation" Version="6.1.0" />
75+
</ItemGroup>
76+
77+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Release'">
78+
<PackageReference Include="System.Management.Automation" Version="7.0.0" />
79+
</ItemGroup>
80+
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Release'">
81+
<DefineConstants>$(DefineConstants);PSV7;CORECLR</DefineConstants>
82+
</PropertyGroup>
83+
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Release'">
84+
<DefineConstants>$(DefineConstants);PSV6;CORECLR</DefineConstants>
85+
</PropertyGroup>
86+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Release'">
6587
<PackageReference Include="System.Management.Automation" Version="6.1.0" />
6688
</ItemGroup>
6789

Engine/PSScriptAnalyzer.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Author = 'Microsoft Corporation'
1111
RootModule = 'PSScriptAnalyzer.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '1.18.3'
14+
ModuleVersion = '1.19.0'
1515

1616
# ID used to uniquely identify this module
1717
GUID = 'd6245802-193d-4068-a631-8863a4342a18'

Engine/PSScriptAnalyzer.psm1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ $PSModuleRoot = $PSModule.ModuleBase
99

1010
# Import the appropriate nested binary module based on the current PowerShell version
1111
$binaryModuleRoot = $PSModuleRoot
12-
13-
14-
if (($PSVersionTable.Keys -contains "PSEdition") -and ($PSVersionTable.PSEdition -ne 'Desktop')) {
15-
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath 'coreclr'
12+
if ($PSVersionTable.PSVersion.Major -eq 7 ) {
13+
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath "PSv$($PSVersionTable.PSVersion.Major)"
14+
}
15+
elseif ($PSVersionTable.PSVersion.Major -eq 6 ) {
16+
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath "PSv$($PSVersionTable.PSVersion.Major)"
1617
# Minimum PowerShell Core version given by PowerShell Core support itself and
1718
# also the version of NewtonSoft.Json implicitly that PSSA ships with,
1819
# which cannot be higher than the one that PowerShell ships with.
19-
[Version] $minimumPowerShellCoreVersion = '6.2.1'
20+
[Version] $minimumPowerShellCoreVersion = '6.2.4'
2021
if ($PSVersionTable.PSVersion -lt $minimumPowerShellCoreVersion) {
2122
throw "Minimum supported version of PSScriptAnalyzer for PowerShell Core is $minimumPowerShellCoreVersion but current version is '$($PSVersionTable.PSVersion)'. Please update PowerShell Core."
2223
}

Rules/Rules.csproj

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>1.18.3</VersionPrefix>
5-
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
4+
<VersionPrefix>1.19.0</VersionPrefix>
5+
<TargetFrameworks>netcoreapp3.1;netstandard2.0;net452</TargetFrameworks>
66
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules</AssemblyName>
77
<PackageId>Rules</PackageId>
88
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
99
</PropertyGroup>
1010

1111
<ItemGroup>
1212
<ProjectReference Include="..\Engine\Engine.csproj" />
13-
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
14-
<PackageReference Include="Microsoft.Management.Infrastructure" Version="1.0.0" />
13+
<ProjectReference Include="..\PSCompatibilityCollector\Microsoft.PowerShell.CrossCompatibility\Microsoft.PowerShell.CrossCompatibility.csproj" />
14+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
15+
</ItemGroup>
16+
17+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netcoreapp3.1' ">
18+
<PackageReference Include="Microsoft.Management.Infrastructure" Version="2.0.0" />
1519
</ItemGroup>
1620

1721
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
22+
<PackageReference Include="Microsoft.Management.Infrastructure" Version="1.0.0" />
1823
<Reference Include="System.ComponentModel.Composition" />
1924
<Reference Include="System.Data.Entity.Design" />
2025
</ItemGroup>
@@ -42,15 +47,11 @@
4247
</EmbeddedResource>
4348
</ItemGroup>
4449

45-
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
50+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netcoreapp3.1'">
4651
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.5.1" />
4752
<Compile Remove="UseSingularNouns.cs" />
4853
</ItemGroup>
4954

50-
<ItemGroup>
51-
<ProjectReference Include="..\PSCompatibilityCollector\Microsoft.PowerShell.CrossCompatibility\Microsoft.PowerShell.CrossCompatibility.csproj" />
52-
</ItemGroup>
53-
5455
<PropertyGroup Condition=" '$(Configuration)' == 'PSV3Release' ">
5556
<DefineConstants>$(DefineConstants);PSV3</DefineConstants>
5657
</PropertyGroup>
@@ -67,4 +68,36 @@
6768
<DefineConstants>$(DefineConstants);PSV3;PSV4</DefineConstants>
6869
</PropertyGroup>
6970

71+
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Release'">
72+
<DefineConstants>$(DefineConstants);PSV7;CORECLR</DefineConstants>
73+
</PropertyGroup>
74+
75+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Release'">
76+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.0" />
77+
</ItemGroup>
78+
79+
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Release'">
80+
<DefineConstants>$(DefineConstants);PSV6;CORECLR</DefineConstants>
81+
</PropertyGroup>
82+
83+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Release'">
84+
<PackageReference Include="System.Management.Automation" Version="6.1.0" />
85+
</ItemGroup>
86+
87+
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Debug'">
88+
<DefineConstants>$(DefineConstants);PSV7;CORECLR</DefineConstants>
89+
</PropertyGroup>
90+
91+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Debug'">
92+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.0" />
93+
</ItemGroup>
94+
95+
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Debug'">
96+
<DefineConstants>$(DefineConstants);PSV6;CORECLR</DefineConstants>
97+
</PropertyGroup>
98+
99+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Debug'">
100+
<PackageReference Include="System.Management.Automation" Version="6.1.0" />
101+
</ItemGroup>
102+
70103
</Project>

build.ps1

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ param(
3636
[Parameter(ParameterSetName='Bootstrap')]
3737
[switch] $Bootstrap
3838
)
39-
BEGIN {
40-
if ($PSVersion -gt 6) {
41-
# due to netstandard2.0 we do not need to treat PS version 7 differently
42-
$PSVersion = 6
43-
}
44-
}
4539

4640
END {
4741
Import-Module -Force (Join-Path $PSScriptRoot build.psm1)

build.psm1

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ function Start-ScriptAnalyzerBuild
144144
param (
145145
[switch]$All,
146146

147-
# Note that 6 should also be chosen for PowerShell7 as both implement netstandard2.0
148-
# and we do not use features from netstandard2.1
149-
[ValidateRange(3, 6)]
147+
[ValidateRange(3, 7)]
150148
[int]$PSVersion = $PSVersionTable.PSVersion.Major,
151149

152150
[ValidateSet("Debug", "Release")]
@@ -178,7 +176,7 @@ function Start-ScriptAnalyzerBuild
178176
if ( $All )
179177
{
180178
# Build all the versions of the analyzer
181-
foreach($psVersion in 3..6) {
179+
foreach($psVersion in 3..7) {
182180
Start-ScriptAnalyzerBuild -Configuration $Configuration -PSVersion $psVersion
183181
}
184182
return
@@ -191,15 +189,18 @@ function Start-ScriptAnalyzerBuild
191189
Set-Variable -Name profilesCopied -Value $true -Scope 1
192190
}
193191

194-
if ($PSVersion -ge 6) {
192+
if ($PSVersion -eq 7) {
193+
$framework = 'netcoreapp3.1'
194+
}
195+
elseif ($PSVersion -eq 6) {
195196
$framework = 'netstandard2.0'
196197
}
197198
else {
198199
$framework = "net452"
199200
}
200201

201202
# build the appropriate assembly
202-
if ($PSVersion -match "[34]" -and $Framework -eq "core")
203+
if ($PSVersion -match "[34]" -and $Framework -ne "net452")
203204
{
204205
throw ("ScriptAnalyzer for PS version '{0}' is not applicable to {1} framework" -f $PSVersion,$Framework)
205206
}
@@ -231,7 +232,11 @@ function Start-ScriptAnalyzerBuild
231232
}
232233
6
233234
{
234-
$destinationDirBinaries = "$script:destinationDir\coreclr"
235+
$destinationDirBinaries = "$script:destinationDir\PSv6"
236+
}
237+
7
238+
{
239+
$destinationDirBinaries = "$script:destinationDir\PSv7"
235240
}
236241
default
237242
{
@@ -240,7 +245,7 @@ function Start-ScriptAnalyzerBuild
240245
}
241246

242247
$buildConfiguration = $Configuration
243-
if ((3, 4) -contains $PSVersion) {
248+
if ((3, 4, 6, 7) -contains $PSVersion) {
244249
$buildConfiguration = "PSV${PSVersion}${Configuration}"
245250
}
246251

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "3.1.102"
3+
"version": "3.1.101"
44
}
55
}

tools/releaseBuild/FileCatalogSigning.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<SignConfigXML>
33
<!-- ****Begin**** BothDual - Dual (Sha256 and Sha1) AuthenticodeDual) and should be StrongName, but we will add this in 6.1.0 ******** -->
44
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer File Catalog" approvers="vigarg;gstolt">
5-
<file src="__INPATHROOT__\PSScriptAnalyzer\1.18.3\PSScriptAnalyzer.cat" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.18.3\PSScriptAnalyzer.cat" />
5+
<file src="__INPATHROOT__\PSScriptAnalyzer\1.19.0\PSScriptAnalyzer.cat" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSScriptAnalyzer.cat" />
66
</job>
77
<!-- <job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Compatibility Analyzer File Catalog" approvers="vigarg;gstolt">
88
<file src="__INPATHROOT__\PSCompatibilityCollector\PSCompatibilityCollector.cat" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\PSCompatibilityAnalzyer.cat" />

tools/releaseBuild/Image/DockerFile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# escape=`
22
#0.3.6 (no powershell 6)
33
# FROM microsoft/windowsservercore
4-
FROM microsoft/dotnet-framework:4.7.1
4+
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8
55
LABEL maintainer='PowerShell Team <[email protected]>'
66
LABEL description="This Dockerfile for Windows Server Core with git installed via chocolatey."
77

@@ -14,20 +14,14 @@ COPY dockerInstall.psm1 containerFiles/dockerInstall.psm1
1414
RUN Import-Module PackageManagement; `
1515
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force; `
1616
Import-Module ./containerFiles/dockerInstall.psm1; `
17+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12; `
1718
Install-ChocolateyPackage -PackageName git -Executable git.exe; `
1819
Install-ChocolateyPackage -PackageName nuget.commandline -Executable nuget.exe -Cleanup; `
1920
Install-Module -Force -Name platyPS -Repository PSGallery; `
2021
Invoke-WebRequest -Uri https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1 -outfile C:/dotnet-install.ps1; `
2122
C:/dotnet-install.ps1 -Channel Release -Version 2.1.4; `
2223
Add-Path C:/Users/ContainerAdministrator/AppData/Local/Microsoft/dotnet;
2324

24-
RUN Import-Module ./containerFiles/dockerInstall.psm1; `
25-
# git clone https://Github.com/PowerShell/PSScriptAnalyzer; `
26-
Install-ChocolateyPackage -PackageName dotnet4.5;
27-
28-
RUN Import-Module ./containerFiles/dockerInstall.psm1; `
29-
Install-ChocolateyPackage -PackageName netfx-4.5.2-devpack;
30-
3125
COPY buildPSSA.ps1 containerFiles/buildPSSA.ps1
3226

3327
ENTRYPOINT ["C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"]

0 commit comments

Comments
 (0)