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

Changes to build analyzer for PS7 and PS6 and ship in separate directories and bump version to 1.19.0 #1425

Merged
merged 13 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
28 changes: 25 additions & 3 deletions Engine/Engine.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>1.18.3</VersionPrefix>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<VersionPrefix>1.19.0</VersionPrefix>
<TargetFrameworks>netcoreapp3.1;netstandard2.0;net452</TargetFrameworks>
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer</AssemblyName>
<PackageId>Engine</PackageId>
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
Expand Down Expand Up @@ -61,7 +61,29 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Debug'">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.0" />
</ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Debug'">
<DefineConstants>$(DefineConstants);PSV7;CORECLR</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Debug'">
<DefineConstants>$(DefineConstants);PSV6;CORECLR</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Debug'">
<PackageReference Include="System.Management.Automation" Version="6.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Release'">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.0" />
</ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Release'">
<DefineConstants>$(DefineConstants);PSV7;CORECLR</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Release'">
<DefineConstants>$(DefineConstants);PSV6;CORECLR</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Release'">
<PackageReference Include="System.Management.Automation" Version="6.1.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Engine/PSScriptAnalyzer.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Author = 'Microsoft Corporation'
RootModule = 'PSScriptAnalyzer.psm1'

# Version number of this module.
ModuleVersion = '1.18.3'
ModuleVersion = '1.19.0'

# ID used to uniquely identify this module
GUID = 'd6245802-193d-4068-a631-8863a4342a18'
Expand Down
8 changes: 6 additions & 2 deletions Engine/PSScriptAnalyzer.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ $PSModuleRoot = $PSModule.ModuleBase
$binaryModuleRoot = $PSModuleRoot


if (($PSVersionTable.Keys -contains "PSEdition") -and ($PSVersionTable.PSEdition -ne 'Desktop')) {
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath 'coreclr'
# if (($PSVersionTable.Keys -contains "PSEdition") -and ($PSVersionTable.PSEdition -ne 'Desktop')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please cleanup this commented out line

if ($PSVersionTable.PSVersion.Major -eq 7 ) {
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath "PSv$($PSVersionTable.PSVersion.Major)"
}
elseif ($PSVersionTable.PSVersion.Major -eq 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.
Expand Down
36 changes: 31 additions & 5 deletions Rules/Rules.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>1.18.3</VersionPrefix>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<VersionPrefix>1.19.0</VersionPrefix>
<TargetFrameworks>netcoreapp3.1;netstandard2.0;net452</TargetFrameworks>
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules</AssemblyName>
<PackageId>Rules</PackageId>
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Engine\Engine.csproj" />
Copy link
Collaborator

@bergmeister bergmeister Mar 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is common amongst all compilations and is therefore duplicated. Please move it into its own ItemGroup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Microsoft.Management.Infrastructure" Version="1.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
bergmeister marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="Microsoft.Management.Infrastructure" Version="2.0.0" />
rjmholt marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
Expand Down Expand Up @@ -42,7 +42,7 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.5.1" />
<Compile Remove="UseSingularNouns.cs" />
</ItemGroup>
Expand All @@ -67,4 +67,30 @@
<DefineConstants>$(DefineConstants);PSV3;PSV4</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Release'">
<DefineConstants>$(DefineConstants);PSV7;CORECLR</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Release'">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.0" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the SDK and not SMA?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strictly speaking, SMA should have never been used, but the SDK did not exist. Using the SDK is the guidance we're providing.

</ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Release'">
<DefineConstants>$(DefineConstants);PSV6;CORECLR</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Release'">
<PackageReference Include="System.Management.Automation" Version="6.1.0" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Debug'">
<DefineConstants>$(DefineConstants);PSV7;CORECLR</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1' AND '$(Configuration)' == 'PSV7Debug'">
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.0" />
</ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Debug'">
<DefineConstants>$(DefineConstants);PSV6;CORECLR</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' AND '$(Configuration)' == 'PSV6Debug'">
<PackageReference Include="System.Management.Automation" Version="6.1.0" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ param(
[switch] $Bootstrap
)
BEGIN {
if ($PSVersion -gt 6) {
# due to netstandard2.0 we do not need to treat PS version 7 differently
$PSVersion = 6
}
#if ($PSVersion -gt 6) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented out code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

# # due to netstandard2.0 we do not need to treat PS version 7 differently
# $PSVersion = 6
#}
}

END {
Expand Down
21 changes: 13 additions & 8 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ function Start-ScriptAnalyzerBuild
param (
[switch]$All,

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

[ValidateSet("Debug", "Release")]
Expand Down Expand Up @@ -178,7 +176,7 @@ function Start-ScriptAnalyzerBuild
if ( $All )
{
# Build all the versions of the analyzer
foreach($psVersion in 3..6) {
foreach($psVersion in 3..7) {
Start-ScriptAnalyzerBuild -Configuration $Configuration -PSVersion $psVersion
}
return
Expand All @@ -191,15 +189,18 @@ function Start-ScriptAnalyzerBuild
Set-Variable -Name profilesCopied -Value $true -Scope 1
}

if ($PSVersion -ge 6) {
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 -eq "core")
if ($PSVersion -match "[34]" -and $Framework -ne "net452")
{
throw ("ScriptAnalyzer for PS version '{0}' is not applicable to {1} framework" -f $PSVersion,$Framework)
}
Expand Down Expand Up @@ -231,7 +232,11 @@ function Start-ScriptAnalyzerBuild
}
6
{
$destinationDirBinaries = "$script:destinationDir\coreclr"
$destinationDirBinaries = "$script:destinationDir\PSv6"
}
7
{
$destinationDirBinaries = "$script:destinationDir\PSv7"
}
default
{
Expand All @@ -240,7 +245,7 @@ function Start-ScriptAnalyzerBuild
}

$buildConfiguration = $Configuration
if ((3, 4) -contains $PSVersion) {
if ((3, 4, 6, 7) -contains $PSVersion) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because only 7 is special, wouldn't code be simpler if we didn't add 6 so that we would only need the PSVersion7 constant in the csproj file but not PSVersion6?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly, but i thought it would be better to be more complete and treat 5 as the only special one. Since assemblies are put in special directories, i thought it was best to provide constants that could be used

$buildConfiguration = "PSV${PSVersion}${Configuration}"
}

Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.1.102"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this change? This seems to be a downgrade

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jim mentioned on Slack it didn't work with 102 but only 101. Def something that would be interesting to know but I am not too worried about being one patch behind since PSSA is not a self-contained app

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was a vsts build problem - for some reason the VSTS build machine couldn't download 102 - i didn't spend the time to find out why since it was just a single patch (for the SDK)

"version": "3.1.101"
}
}
2 changes: 1 addition & 1 deletion tools/releaseBuild/FileCatalogSigning.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<SignConfigXML>
<!-- ****Begin**** BothDual - Dual (Sha256 and Sha1) AuthenticodeDual) and should be StrongName, but we will add this in 6.1.0 ******** -->
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer File Catalog" approvers="vigarg;gstolt">
<file src="__INPATHROOT__\PSScriptAnalyzer\1.18.3\PSScriptAnalyzer.cat" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.18.3\PSScriptAnalyzer.cat" />
<file src="__INPATHROOT__\PSScriptAnalyzer\1.19.0\PSScriptAnalyzer.cat" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\1.19.0\PSScriptAnalyzer.cat" />
</job>
<!-- <job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Compatibility Analyzer File Catalog" approvers="vigarg;gstolt">
<file src="__INPATHROOT__\PSCompatibilityCollector\PSCompatibilityCollector.cat" signType="Authenticode" dest="__OUTPATHROOT__\PSCompatibilityCollector\PSCompatibilityAnalzyer.cat" />
Expand Down
11 changes: 6 additions & 5 deletions tools/releaseBuild/Image/DockerFile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# escape=`
#0.3.6 (no powershell 6)
# FROM microsoft/windowsservercore
FROM microsoft/dotnet-framework:4.7.1
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8
LABEL maintainer='PowerShell Team <[email protected]>'
LABEL description="This Dockerfile for Windows Server Core with git installed via chocolatey."

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

RUN Import-Module ./containerFiles/dockerInstall.psm1; `
#RUN Import-Module ./containerFiles/dockerInstall.psm1; `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth removing this entirely if we're no longer using this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

# git clone https://Github.com/PowerShell/PSScriptAnalyzer; `
Install-ChocolateyPackage -PackageName dotnet4.5;
# Install-ChocolateyPackage -PackageName dotnet4.5;

RUN Import-Module ./containerFiles/dockerInstall.psm1; `
Install-ChocolateyPackage -PackageName netfx-4.5.2-devpack;
#RUN Import-Module ./containerFiles/dockerInstall.psm1; `
# Install-ChocolateyPackage -PackageName netfx-4.5.2-devpack;

COPY buildPSSA.ps1 containerFiles/buildPSSA.ps1

Expand Down
Loading