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

Pin assembly versions to prevent revving those in servicing releases #6101

Merged
merged 2 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 19 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionPrefix>6.0.3</VersionPrefix>
<MajorVersion>6</MajorVersion>
<MinorVersion>0</MinorVersion>
<PatchVersion>3</PatchVersion>
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>

<!--
Set assembly version to align with major and minor version, as for the patches and revisions should be manually
updated per assembly if it is serviced.

Note, any components that aren't exposed as references in the targeting pack (like analyzers/generators) those should rev
so that they can exist sxs. The compiler relies on different version to change assembly version for caching purposes.

Because it is possible to build on a lower version and run on a higher version, we're locking the targeting pack and the runtime
assembly vesions to 6.0.2.
There's still a risk that some customers building on 6.0.2+ and trying to run on 6.0.0 and 6.0.1 will still have issue, but
those issues can be mitigated with a workaround described in https://github.com/dotnet/core/issues/7176.
-->
<AssemblyVersion>$(MajorVersion).$(MinorVersion).2.0</AssemblyVersion>
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as on the WinForms PR, using the .2 patch version should be conditioned on whether we're building for 6.0, and should not apply to 7.0 and forwards.

Copy link
Contributor

Choose a reason for hiding this comment

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

Version here must be 6.0.0.0 or simply 6.0. At least from my point of view and past experience with version pinning.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same comment as on the WinForms PR, using the .2 patch version should be conditioned on whether we're building for 6.0, and should not apply to 7.0 and forwards.

This is a 6.0 branch. For the 7.0 branch it is locked at Major.Minor.0.0, see #6099.
Is there a situation where you expect 6.0 spill into another branch?


<PreReleaseVersionLabel>servicing</PreReleaseVersionLabel>
<PreReleaseVersionIteration>
</PreReleaseVersionIteration>
Expand Down
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."
RussKie marked this conversation as resolved.
Show resolved Hide resolved
exit -1;
}
}
44 changes: 44 additions & 0 deletions packaging/Microsoft.DotNet.Wpf.GitHub/Directory.Build.targets
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)' == ''">C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</_PowerShellExe>
RussKie marked this conversation as resolved.
Show resolved Hide resolved
<_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 &quot;&amp; { &amp;&apos;$(_ScriptLocation)&apos; &apos;$(_NuspecFilePath)&apos; &apos;$(AssemblyVersion)&apos; $(_IsServicingRelease) } &quot;"
ContinueOnError="False" />

</Target>

</Project>