From 4c2bc090ca54f563987135f7d60533178fa22e95 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Thu, 10 Feb 2022 13:37:29 +1100 Subject: [PATCH] Pin assembly versions to prevent revving those in servicing releases --- eng/Versions.props | 36 ++++++---- .../Check-AssemblyVersions.ps1 | 66 +++++++++++++++++++ .../Directory.Build.targets | 44 +++++++++++++ 3 files changed, 135 insertions(+), 11 deletions(-) create mode 100644 packaging/Microsoft.DotNet.Wpf.GitHub/Check-AssemblyVersions.ps1 create mode 100644 packaging/Microsoft.DotNet.Wpf.GitHub/Directory.Build.targets diff --git a/eng/Versions.props b/eng/Versions.props index 781ac6f9799..e877d2bac46 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -1,32 +1,46 @@ - 7.0.0 + 7 + 0 + 0 preview 2 - 7.0.0-preview.2.22113.2 - 7.0.0-preview.2.22113.2 + + $(MajorVersion).$(MinorVersion).$(PatchVersion) + + + $(MajorVersion).$(MinorVersion).0.0 - + + 7.0.0-preview.2.22114.4 - + 7.0.0-preview.2.22113.2 7.0.0-preview.2.22113.2 7.0.0-preview.2.22113.2 7.0.0-preview.2.22113.2 - 7.0.0-preview.2.22113.2 - 7.0.0-preview.2.22113.2 - 7.0.0-preview.2.22113.2 - - - 7.0.0-preview.2.22113.2 7.0.0-preview.2.22113.2 7.0.0-preview.2.22113.2 + 7.0.0-preview.2.22113.2 + 7.0.0-preview.2.22113.2 + 7.0.0-preview.2.22113.2 + 7.0.0-preview.2.22113.2 4.6.0-preview4.19176.11 + 7.0.0-preview.2.22113.2 7.0.0-preview.2.22113.2 7.0.0-preview.2.22113.2 7.0.0-preview.2.22113.2 diff --git a/packaging/Microsoft.DotNet.Wpf.GitHub/Check-AssemblyVersions.ps1 b/packaging/Microsoft.DotNet.Wpf.GitHub/Check-AssemblyVersions.ps1 new file mode 100644 index 00000000000..84061f7fdc7 --- /dev/null +++ b/packaging/Microsoft.DotNet.Wpf.GitHub/Check-AssemblyVersions.ps1 @@ -0,0 +1,66 @@ +[CmdletBinding(PositionalBinding=$false)] +Param( + [Parameter(Mandatory=$True, Position=1)] + [string] $NuspecFile, + [Parameter(Mandatory=$True, Position=2)] + [string] $ExpectedAssemblyVersion, + [Parameter(Mandatory=$True, Position=3)] + [string] $IsServicingRelease, + [Parameter(ValueFromRemainingArguments=$true)][String[]] $properties +) + +$servicingRelease = $null; +[bool]::TryParse($IsServicingRelease, [ref]$servicingRelease) | Out-Null; + +[xml] $xmlDoc = Get-Content -Path $NuspecFile -Force; + +# +# Verify that components that are exposed as references in the targeting packs don't have their versions revved. +# See https://github.com/dotnet/core/issues/7172#issuecomment-1034105137 for more details. +[xml] $xmlDoc = Get-Content -Path $NuspecFile -Force; + +# Iterate over files that MUST NOT have their versions revved with every release +$nonRevAssemblies = $xmlDoc.package.files.file | ` + Where-Object { + ($_.target.StartsWith('lib\') -or $_.target.StartsWith('ref\')) ` + -and $_.target.EndsWith('.dll', [System.StringComparison]::OrdinalIgnoreCase) ` + -and !$_.target.EndsWith('resources.dll', [System.StringComparison]::OrdinalIgnoreCase) + } | ` + Select-Object -Unique src | ` + Select-Object -ExpandProperty src; + +$nonRevAssemblies | ` + sort-object | ` + foreach-object { + $assembly = $_; + [string] $version = ([Reflection.AssemblyName]::GetAssemblyName($assembly).Version).ToString() + + Write-Host "$assembly`: $version" + if (![string]::Equals($version, $ExpectedAssemblyVersion)) { + throw "$assembly is not versioned correctly. Expected: '$ExpectedAssemblyVersion', found: '$version'." + exit -1; + } + } + +# Iterate over files that MUST have their versions revved with every release +$revAssemblies = $xmlDoc.package.files.file | ` + Where-Object { + $_.target.StartsWith('sdk\analyzers\') ` + -and $_.target.EndsWith('.dll', [System.StringComparison]::OrdinalIgnoreCase) ` + -and !$_.target.EndsWith('resources.dll', [System.StringComparison]::OrdinalIgnoreCase) + } | ` + Select-Object -Unique src | ` + Select-Object -ExpandProperty src; + +$revAssemblies | ` + sort-object | ` + foreach-object { + $assembly = $_; + [string] $version = ([Reflection.AssemblyName]::GetAssemblyName($assembly).Version).ToString() + + Write-Host "$assembly`: $version" + if ($servicingRelease -and [string]::Equals($version, $ExpectedAssemblyVersion)) { + throw "$assembly is not versioned correctly. '$version' is not expected." + exit -1; + } + } diff --git a/packaging/Microsoft.DotNet.Wpf.GitHub/Directory.Build.targets b/packaging/Microsoft.DotNet.Wpf.GitHub/Directory.Build.targets new file mode 100644 index 00000000000..8c7d21671a3 --- /dev/null +++ b/packaging/Microsoft.DotNet.Wpf.GitHub/Directory.Build.targets @@ -0,0 +1,44 @@ + + + + + + <_PowerShellExe Condition="'$(_PowerShellExe)' == ''">%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe + <_ScriptLocation Condition="'$(_ScriptLocation)' == ''">$(MSBuildProjectDirectory)\Check-AssemblyVersions.ps1 + <_IsServicingRelease>false + <_IsServicingRelease Condition="'$(PreReleaseVersionLabel)' == 'servicing'">true + + + + + + <_NuspecFile Include="@(NuGetPackOutput)" Condition="'%(Extension)' == '.nuspec'" /> + + + + <_NuspecFilePath>@(_NuspecFile) + + <_NuspecFilePath Condition="'$(_NuspecFilePath)' == '' or !Exists('$(_NuspecFilePath)')">$(NuspecOutputPath)\$(PackageId).$(PackageVersion).nuspec + + + + + + + + + +