Skip to content

Commit

Permalink
Remove conditional compilation for PSv6 and therefore netstandard2.0 …
Browse files Browse the repository at this point in the history
…for Engine and Rules projects (#1600)
  • Loading branch information
bergmeister authored Nov 10, 2020
1 parent a0f9822 commit 965eca5
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 59 deletions.
12 changes: 3 additions & 9 deletions Engine/Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<VersionPrefix>1.19.1</VersionPrefix>
<TargetFrameworks>netcoreapp3.1;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net452</TargetFrameworks>
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer</AssemblyName>
<AssemblyVersion>1.19.1</AssemblyVersion>
<PackageId>Engine</PackageId>
Expand All @@ -17,11 +17,11 @@
<DebugType>portable</DebugType>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netcoreapp3.1' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<DefineConstants>$(DefineConstants);CORECLR</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netcoreapp3.1' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<Compile Remove="SafeDirectoryCatalog.cs" />
</ItemGroup>

Expand Down Expand Up @@ -68,12 +68,6 @@
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<DefineConstants>$(DefineConstants);PSV7;CORECLR</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<DefineConstants>$(DefineConstants);PSV6;CORECLR</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Management.Automation" Version="6.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net452' AND '$(Configuration)' == 'PSV3Release' AND '$(Configuration)' != 'PSV4Release'">
<PackageReference Include="Microsoft.PowerShell.3.ReferenceAssemblies" Version="1.0.0" />
Expand Down
12 changes: 5 additions & 7 deletions Engine/PSScriptAnalyzer.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ $PSModuleRoot = $PSModule.ModuleBase

# Import the appropriate nested binary module based on the current PowerShell version
$binaryModuleRoot = $PSModuleRoot
if ($PSVersionTable.PSVersion.Major -eq 7 ) {
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath "PSv$($PSVersionTable.PSVersion.Major)"
}
elseif ($PSVersionTable.PSVersion.Major -eq 6 ) {
[Version] $minimumPowerShellCoreVersion = '7.0.3'
if ($PSVersionTable.PSVersion.Major -ge 6) {
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath "PSv$($PSVersionTable.PSVersion.Major)"
# Minimum PowerShell Core version given by PowerShell Core support itself and
# also the version of NewtonSoft.Json implicitly that PSSA ships with,
# which cannot be higher than the one that PowerShell ships with.
[Version] $minimumPowerShellCoreVersion = '6.2.4'
# the version of Nuget references, such as e.g. Newtonsoft.Json inside PowerShell itself
# or the version of the System.Management.Automation NuGet reference in PSSA.

if ($PSVersionTable.PSVersion -lt $minimumPowerShellCoreVersion) {
throw "Minimum supported version of PSScriptAnalyzer for PowerShell Core is $minimumPowerShellCoreVersion but current version is '$($PSVersionTable.PSVersion)'. Please update PowerShell Core."
}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Exit
#### Supported PowerShell Versions and Platforms

- Windows PowerShell 3.0 or greater
- PowerShell Core 6.2 or greater on Windows/Linux/macOS
- PowerShell Core 7.0.3 or greater on Windows/Linux/macOS
- Docker (tested only using Docker Desktop on Windows 10 1809)
- PowerShell 6 Windows Image tags from [mcr.microsoft.com/powershell](https://hub.docker.com/r/microsoft/powershell). Example (1 warning gets produced by `Save-Module` but can be ignored):

Expand Down Expand Up @@ -141,9 +141,9 @@ Note: the PSScriptAnalyzer Chocolatey package is provided and supported by the c
```powershell
.\build.ps1 -PSVersion 3
```
* PowerShell Core
* PowerShell 7
```powershell
.\build.ps1 -PSVersion 6
.\build.ps1 -PSVersion 7
```
* Rebuild documentation since it gets built automatically only the first time
```powershell
Expand Down
21 changes: 7 additions & 14 deletions Rules/Rules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<VersionPrefix>1.19.1</VersionPrefix>
<TargetFrameworks>netcoreapp3.1;netstandard2.0;net452</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net452</TargetFrameworks>
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules</AssemblyName>
<AssemblyVersion>1.19.1</AssemblyVersion>
<PackageId>Rules</PackageId>
Expand All @@ -15,6 +15,12 @@
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
<PackageReference Include="Microsoft.Management.Infrastructure" Version="2.0.0" />
<Compile Remove="UseSingularNouns.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Data.Entity.Design" />
Expand All @@ -24,10 +30,6 @@
<DebugType>portable</DebugType>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>$(DefineConstants);CORECLR</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Update="Strings.Designer.cs">
<DesignTime>True</DesignTime>
Expand All @@ -42,11 +44,6 @@
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
<Compile Remove="UseSingularNouns.cs" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'PSV3Release' OR '$(Configuration)' == 'PSV3Debug'">
<DefineConstants>$(DefineConstants);PSV3</DefineConstants>
Expand All @@ -60,8 +57,4 @@
<DefineConstants>$(DefineConstants);PSV7;CORECLR</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<DefineConstants>$(DefineConstants);PSV6;CORECLR</DefineConstants>
</PropertyGroup>

</Project>
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ build_script:
- pwsh: |
if ($env:PowerShellEdition -eq 'PowerShellCore') {
Set-Location $env:APPVEYOR_BUILD_FOLDER
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 6
./PSCompatibilityCollector/build.ps1 -Configuration "$env:BuildConfiguration" -Framework 'netstandard2.0'
./build.ps1 -Configuration "$env:BuildConfiguration" -PSVersion 7
./PSCompatibilityCollector/build.ps1 -Configuration "$env:BuildConfiguration" -Framework 'netcoreapp3.1'
}
test_script:
Expand Down
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ param(
[switch]$All,

[Parameter(ParameterSetName="BuildOne")]
[ValidateRange(3, 7)]
[ValidateSet(3, 4, 5, 7)]
[int]$PSVersion = $PSVersionTable.PSVersion.Major,

[Parameter(ParameterSetName="BuildOne")]
Expand Down
17 changes: 4 additions & 13 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function Start-ScriptAnalyzerBuild
param (
[switch]$All,

[ValidateRange(3, 7)]
[ValidateSet(3, 4, 5, 7)]
[int]$PSVersion = $PSVersionTable.PSVersion.Major,

[ValidateSet("Debug", "Release")]
Expand Down Expand Up @@ -183,7 +183,7 @@ function Start-ScriptAnalyzerBuild
if ( $All )
{
# Build all the versions of the analyzer
foreach($psVersion in 3..7) {
foreach ($psVersion in 3, 4, 5, 7) {
Start-ScriptAnalyzerBuild -Configuration $Configuration -PSVersion $psVersion -Verbose:$verboseWanted
}
if ( $Catalog ) {
Expand All @@ -200,15 +200,10 @@ function Start-ScriptAnalyzerBuild
Set-Variable -Name profilesCopied -Value $true -Scope 1
}

$framework = 'net452'
if ($PSVersion -eq 7) {
$framework = 'netcoreapp3.1'
}
elseif ($PSVersion -eq 6) {
$framework = 'netstandard2.0'
}
else {
$framework = "net452"
}

# build the appropriate assembly
if ($PSVersion -match "[34]" -and $Framework -ne "net452")
Expand Down Expand Up @@ -241,10 +236,6 @@ function Start-ScriptAnalyzerBuild
{
$destinationDirBinaries = "$script:destinationDir"
}
6
{
$destinationDirBinaries = "$script:destinationDir\PSv6"
}
7
{
$destinationDirBinaries = "$script:destinationDir\PSv7"
Expand All @@ -256,7 +247,7 @@ function Start-ScriptAnalyzerBuild
}

$buildConfiguration = $Configuration
if ((3, 4, 6, 7) -contains $PSVersion) {
if ((3, 4, 7) -contains $PSVersion) {
$buildConfiguration = "PSV${PSVersion}${Configuration}"
}

Expand Down
5 changes: 0 additions & 5 deletions tools/releaseBuild/AssemblySignConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\Settings\ScriptingStyle.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\Settings\ScriptingStyle.psd1" />
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\Settings\ScriptSecurity.psd1" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\Settings\ScriptSecurity.psd1" />
</job>
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer PSv6" approvers="vigarg;gstolt">
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\PSv6\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\PSv6\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" />
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\PSv6\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\PSv6\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" />
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\PSv6\Microsoft.PowerShell.CrossCompatibility.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\PSv6\Microsoft.PowerShell.CrossCompatibility.dll" />
</job>
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer PSv7" approvers="vigarg;gstolt">
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\PSv7\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\PSv7\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" />
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\PSv7\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" signType="400" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\PSv7\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" />
Expand Down
5 changes: 0 additions & 5 deletions tools/releaseBuild/signing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\Settings\ScriptingStyle.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\Settings\ScriptingStyle.psd1" />
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\Settings\ScriptSecurity.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\Settings\ScriptSecurity.psd1" />
</job>
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer PSv6" approvers="vigarg;gstolt">
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\PSv6\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\PSv6\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" />
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\PSv6\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\PSv6\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" />
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\PSv6\Microsoft.PowerShell.CrossCompatibility.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\PSv6\Microsoft.PowerShell.CrossCompatibility.dll" />
</job>
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer PSv7" approvers="vigarg;gstolt">
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\PSv7\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\PSv7\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" />
<file src="__INPATHROOT__\out\PSScriptAnalyzer\1.19.1\PSv7\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.1\PSv7\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" />
Expand Down

0 comments on commit 965eca5

Please sign in to comment.