From 1308e27a7426b5d384ef561fbcf8ddeeadf594a7 Mon Sep 17 00:00:00 2001 From: Sridhar Periyasamy Date: Wed, 13 Jan 2016 15:24:09 -0800 Subject: [PATCH] Enable build-to-build major upgrades for MSI. Encode the CLI version into MSI supported ProductVersion documented here - https://msdn.microsoft.com/en-us/library/windows/desktop/aa370859(v=vs.85).aspx Example: CLI Version - 1.0.0.000930 is encoded in MSI as 4.0.930 Prevent downgrading by failing installation with error message. Also display the original CLI version in the ProductName. --- packaging/windows/dotnet.wxs | 11 ++----- packaging/windows/generatemsi.ps1 | 6 +++- packaging/windows/variables.wxi | 3 +- scripts/build/generate-version.ps1 | 52 ++++++++++++++++++++++++++++-- 4 files changed, 60 insertions(+), 12 deletions(-) diff --git a/packaging/windows/dotnet.wxs b/packaging/windows/dotnet.wxs index c3123d83e..2039c237f 100644 --- a/packaging/windows/dotnet.wxs +++ b/packaging/windows/dotnet.wxs @@ -3,13 +3,9 @@ - - - - - - - + + + @@ -22,7 +18,6 @@ - diff --git a/packaging/windows/generatemsi.ps1 b/packaging/windows/generatemsi.ps1 index e5840fb9e..1348921d2 100644 --- a/packaging/windows/generatemsi.ps1 +++ b/packaging/windows/generatemsi.ps1 @@ -63,7 +63,11 @@ function RunCandle Write-Host Running candle.. $AuthWsxRoot = Join-Path $RepoRoot "packaging\windows" - .\candle.exe -dDotnetSrc="$inputDir" -dMicrosoftEula="$RepoRoot\packaging\osx\resources\en.lproj\eula.rtf" -dBuildVersion="$env:DOTNET_CLI_VERSION" -arch x64 ` + .\candle.exe -dDotnetSrc="$inputDir" ` + -dMicrosoftEula="$RepoRoot\packaging\osx\resources\en.lproj\eula.rtf" ` + -dBuildVersion="$env:DOTNET_MSI_VERSION" ` + -dDisplayVersion="$env:DOTNET_CLI_VERSION" ` + -arch x64 ` -ext WixDependencyExtension.dll ` "$AuthWsxRoot\dotnet.wxs" ` "$AuthWsxRoot\provider.wxs" ` diff --git a/packaging/windows/variables.wxi b/packaging/windows/variables.wxi index 05d094005..b14996731 100644 --- a/packaging/windows/variables.wxi +++ b/packaging/windows/variables.wxi @@ -7,12 +7,13 @@ - + + diff --git a/scripts/build/generate-version.ps1 b/scripts/build/generate-version.ps1 index 5d3bad767..f6121df2a 100644 --- a/scripts/build/generate-version.ps1 +++ b/scripts/build/generate-version.ps1 @@ -3,14 +3,62 @@ # Licensed under the MIT license. See LICENSE file in the project root for full license information. # +# MSI versioning +# Encode the CLI version to fit into the MSI versioning scheme - https://msdn.microsoft.com/en-us/library/windows/desktop/aa370859(v=vs.85).aspx +# MSI versions are 3 part +# major.minor.build +# Size(bits) of each part 8 8 16 +# So we have 32 bits to encode the CLI version +# Starting with most significant bit this how the CLI version is going to be encoded as MSI Version +# CLI major -> 6 bits +# CLI minor -> 6 bits +# CLI patch -> 6 bits +# CLI commitcount -> 14 bits +function GetMSIVersionFromCLIVersion([uint32]$Major, [uint32]$Minor, [uint32]$Patch, [uint32]$CommitCount) +{ + if($Major -ge 0x40) + { + throw [System.NotSupportedException] "Invalid Major version - $Major. Major version must be less than 64." + } + + if($Minor -ge 0x40) + { + throw [System.NotSupportedException] "Invalid Minor version - $Minor. Minor version must be less than 64." + } + + if($Patch -ge 0x40) + { + throw [System.NotSupportedException] "Invalid Patch version - $Patch. Patch version must be less than 64." + } + + if($CommitCount -ge 0x4000) + { + throw [System.NotSupportedException] "Invalid CommitCount version - $CommitCount. CommitCount version must be less than 16384." + } + + $Major = ($Major -shl 26) + $Minor = ($Minor -shl 20) + $Patch = ($Patch -shl 14) + [System.UInt32]$MSIVersionNumber = ($Major -bor $Minor -bor $Patch -bor $CommitCount) + + $MSIMajor = ($MSIVersionNumber -shr 24) -band 0xFF + $MSIMinor = ($MSIVersionNumber -shr 16) -band 0xFF + $MSIBuild = $MSIVersionNumber -band 0xFFFF + $MSIVersion = "$MSIMajor.$MSIMinor.$MSIBuild" + + return $MSIVersion +} + $env:ReleaseSuffix = "dev" $env:MajorVersion = 1 $env:MinorVersion = 0 $env:PatchVersion = 0 -$env:CommitCountVersion = (git rev-list --count HEAD).PadLeft(6, "0") +$CommitCount = [int32](git rev-list --count HEAD) +$env:CommitCountVersion = ([string]$CommitCount).PadLeft(6, "0") # Zero Padded Suffix for use with Nuget $env:VersionSuffix = "$env:ReleaseSuffix-$env:CommitCountVersion" -$env:DOTNET_CLI_VERSION = "$env:MajorVersion.$env:MinorVersion.$env:PatchVersion.$env:CommitCountVersion" \ No newline at end of file +$env:DOTNET_CLI_VERSION = "$env:MajorVersion.$env:MinorVersion.$env:PatchVersion.$env:CommitCountVersion" +$env:DOTNET_MSI_VERSION = GetMSIVersionFromCLIVersion $env:MajorVersion $env:MinorVersion $env:PatchVersion $CommitCount