forked from dotnet/wpf
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pin assembly versions to prevent revving those in servicing releases (d…
- Loading branch information
Showing
3 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packaging/Microsoft.DotNet.Wpf.GitHub/Check-AssemblyVersions.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
packaging/Microsoft.DotNet.Wpf.GitHub/Directory.Build.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project> | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" /> | ||
|
||
<PropertyGroup> | ||
<_PowerShellExe Condition="'$(_PowerShellExe)' == ''">%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe</_PowerShellExe> | ||
<_ScriptLocation Condition="'$(_ScriptLocation)' == ''">$(MSBuildProjectDirectory)\Check-AssemblyVersions.ps1</_ScriptLocation> | ||
<_IsServicingRelease>false</_IsServicingRelease> | ||
<_IsServicingRelease Condition="'$(PreReleaseVersionLabel)' == 'servicing'">true</_IsServicingRelease> | ||
</PropertyGroup> | ||
|
||
<!-- | ||
Inspect the following NuSpecs and validate the assembly versions | ||
* .\artifacts\packages\Release\NonShipping\Microsoft.DotNet.Wpf.GitHub.<version>.nuspec produced by Microsoft.DotNet.Wpf.GitHub.ArchNeutral.csproj | ||
* .\artifacts\packages\Release\NonShipping\runtime.<arch>.Microsoft.DotNet.Wpf.GitHub.<version>.nuspec produced by Microsoft.DotNet.Wpf.GitHub.csproj | ||
--> | ||
<Target Name="ValidateTransportPackage" | ||
AfterTargets="GenerateNuspec" | ||
DependsOnTargets="GenerateNuspec" | ||
Condition="'$(IsPackable)' == 'true'"> | ||
<ItemGroup> | ||
<_NuspecFile Include="@(NuGetPackOutput)" Condition="'%(Extension)' == '.nuspec'" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<_NuspecFilePath>@(_NuspecFile)</_NuspecFilePath> | ||
<!-- | ||
When we build Microsoft.DotNet.Wpf.GitHub.csproj GenerateNuspec task creates an arch-specific NuSpec, and | ||
NuSpec declared in NuGetPackOutput does not exist. | ||
Look for the arch-specific NuSpec | ||
--> | ||
<_NuspecFilePath Condition="'$(_NuspecFilePath)' == '' or !Exists('$(_NuspecFilePath)')">$(NuspecOutputPath)\$(PackageId).$(PackageVersion).nuspec</_NuspecFilePath> | ||
</PropertyGroup> | ||
|
||
<Error Text="'$(_ScriptLocation)' is missing." Condition="!Exists('$(_ScriptLocation)')" /> | ||
<Error Text="'$(_NuspecFilePath)' is missing." Condition="!Exists('$(_NuspecFilePath)')" /> | ||
|
||
<Exec | ||
Command="$(_PowerShellExe) -NonInteractive -ExecutionPolicy Unrestricted -Command "& { &'$(_ScriptLocation)' '$(_NuspecFilePath)' '$(AssemblyVersion)' $(_IsServicingRelease) } "" | ||
ContinueOnError="False" /> | ||
|
||
</Target> | ||
|
||
</Project> |