From 147609fdb81c1328d2bb345732bbf30f95470973 Mon Sep 17 00:00:00 2001 From: Igor Velikorossov Date: Tue, 15 Feb 2022 18:06:48 +1100 Subject: [PATCH] Pin assembly versions to prevent revving those in servicing releases (#6101) --- eng/Versions.props | 20 +++++- .../Check-AssemblyVersions.ps1 | 66 +++++++++++++++++++ .../Directory.Build.targets | 44 +++++++++++++ 3 files changed, 129 insertions(+), 1 deletion(-) 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 91d421008..1ef261e9b 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -1,7 +1,25 @@ - 6.0.3 + 6 + 0 + 3 + $(MajorVersion).$(MinorVersion).$(PatchVersion) + + + $(MajorVersion).$(MinorVersion).2.0 + servicing 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 000000000..84061f7fd --- /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 000000000..8c7d21671 --- /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 + + + + + + + + + + -- GitLab