From 8f1a5194c563a3a74e7b92181c87b9e33803c4b4 Mon Sep 17 00:00:00 2001 From: "Raghu Shantha [MSFT]" Date: Tue, 24 May 2016 14:23:38 -0700 Subject: [PATCH] Add MSI package creation capability --- Product.wxs | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ build.psm1 | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 Product.wxs diff --git a/Product.wxs b/Product.wxs new file mode 100644 index 0000000000..1a0b0e44e1 --- /dev/null +++ b/Product.wxs @@ -0,0 +1,81 @@ + + + = 1) OR VersionNT > 601" ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.psm1 b/build.psm1 index 67cb501cc9..784c7f3dc2 100644 --- a/build.psm1 +++ b/build.psm1 @@ -944,3 +944,75 @@ internal class {0} {{ $body -f $ClassName,$ModuleName,$entries } +function Create-MSIPackage +{ + [CmdletBinding()] + param ( + + # Name of the Product + [ValidateNotNullOrEmpty()] + [string] $ProductName = 'OpenPowerShell', + + # Version of the Product + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string] $ProductVersion, + + # Product Guid needs to change for every version to support SxS install + [ValidateNotNullOrEmpty()] + [string] $ProductGuid = 'a5249933-73a1-4b10-8a4c-13c98bdc16fe', + + # Source Path to the Product Files - required to package the contents into an MSI + [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] + [string] $ProductSourcePath, + + # File describing the MSI Package creation semantics + [ValidateNotNullOrEmpty()] + [string] $ProductWxsPath = (Join-Path $pwd 'Product.wxs') + + ) + + $wixToolsetBinPath = "${env:ProgramFiles(x86)}\WiX Toolset v3.10\bin" + + Write-Verbose "Ensure Wix Toolset is present on the machine @ $wixToolsetBinPath" + if (-not (Test-Path $wixToolsetBinPath)) + { + throw "Install Wix Toolset prior to running this script - https://wix.codeplex.com/downloads/get/1540240" + } + + Write-Verbose "Initialize Wix executables - Heat.exe, Candle.exe, Light.exe" + $wixHeatExePath = Join-Path $wixToolsetBinPath "Heat.exe" + $wixCandleExePath = Join-Path $wixToolsetBinPath "Candle.exe" + $wixLightExePath = Join-Path $wixToolsetBinPath "Light.exe" + + $ProductVersion = Split-Path $ProductSourcePath -Leaf + + # Wix tooling does not like hyphen in the foldername + $ProductVersion = $ProductVersion.Replace('-', '_') + + $productVersionWithName = $ProductName + "_" + $ProductVersion + Write-Verbose "Create MSI for Product $productVersionWithName" + + [Environment]::SetEnvironmentVariable("ProductSourcePath", $ProductSourcePath, "Process") + [Environment]::SetEnvironmentVariable("ProductName", $ProductName, "Process") + [Environment]::SetEnvironmentVariable("ProductGuid", $ProductGuid, "Process") + [Environment]::SetEnvironmentVariable("ProductVersion", $ProductVersion, "Process") + [Environment]::SetEnvironmentVariable("ProductVersionWithName", $productVersionWithName, "Process") + + $wixFragmentPath = (Join-path $env:Temp "Fragment.wxs") + $wixObjProductPath = (Join-path $env:Temp "Product.wixobj") + $wixObjFragmentPath = (Join-path $env:Temp "Fragment.wixobj") + + $msiLocationPath = Join-Path $pwd "$productVersionWithName.msi" + del $msiLocationPath -Force + + & $wixHeatExePath dir $ProductSourcePath -dr $productVersionWithName -cg $productVersionWithName -gg -sfrag -srd -scom -sreg -out $wixFragmentPath -var env.ProductSourcePath -v + & $wixCandleExePath "$ProductWxsPath" "$wixFragmentPath" -out (Join-Path "$env:Temp" "\\") -arch x64 -v + & $wixLightExePath -out "$productVersionWithName.msi" $wixObjProductPath $wixObjFragmentPath -ext WixUIExtension -v + + Write-Verbose "You can find the MSI @ $msiLocationPath" + + del *.wixpdb -Force +} +