From 8f1a5194c563a3a74e7b92181c87b9e33803c4b4 Mon Sep 17 00:00:00 2001 From: "Raghu Shantha [MSFT]" Date: Tue, 24 May 2016 14:23:38 -0700 Subject: [PATCH 1/8] 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 000000000..1a0b0e44e --- /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 67cb501cc..784c7f3dc 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 +} + From b4ed5e2534adf82ad7d0fc4fb1cc6e0535bfeaa6 Mon Sep 17 00:00:00 2001 From: Andy Schwartzmeyer Date: Tue, 24 May 2016 14:29:19 -0700 Subject: [PATCH 2/8] Call Create-MSIPackage from Start-PSBuild --- build.psm1 | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/build.psm1 b/build.psm1 index 784c7f3dc..d85967af9 100644 --- a/build.psm1 +++ b/build.psm1 @@ -424,17 +424,23 @@ PowerShell is an open-source, cross-platform, scripting language and rich object Built upon .NET Core, it is also a C# REPL. "@ - if ($IsWindows) { throw "Building Windows packages is not yet supported!" } + # Use Git tag if not given a version + if (-not $Version) { + $Version = (git --git-dir="$PSScriptRoot/.git" describe) -Replace '^v' + } + + $Source = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -Publish)) + Write-Verbose "Packaging $Source" + + if ($IsWindows) { + Create-MSIPackage -ProductSourcePath $Source -ProductVersion $Version -Verbose + return + } if (-not (Get-Command "fpm" -ErrorAction SilentlyContinue)) { throw "Build dependency 'fpm' not found in PATH! See: https://github.com/jordansissel/fpm" } - $Source = Split-Path -Parent (Get-PSOutput) - if ((Split-Path -Leaf $Source) -ne "publish") { - throw "Please Start-PSBuild -Publish with the corresponding runtime for the package" - } - # Decide package output type if (-not $Type) { $Type = if ($IsLinux) { "deb" } elseif ($IsOSX) { "osxpkg" } @@ -456,7 +462,7 @@ Built upon .NET Core, it is also a C# REPL. } New-Item -Force -ItemType SymbolicLink -Path /tmp/powershell -Target $Destination/powershell >$null - + # there is a weired bug in fpm # if the target of the powershell symlink exists, `fpm` aborts # with a `utime` error on OS X. @@ -472,15 +478,9 @@ Built upon .NET Core, it is also a C# REPL. } } - # Change permissions for packaging chmod -R go=u $Source /tmp/powershell - # Use Git tag if not given a version - if (-not $Version) { - $Version = (git --git-dir="$PSScriptRoot/.git" describe) -Replace '^v' - } - $libunwind = switch ($Type) { "deb" { "libunwind8" } "rpm" { "libunwind" } @@ -986,8 +986,6 @@ function Create-MSIPackage $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('-', '_') From 691618d3352ed9329d2f4308683db119d7ceae40 Mon Sep 17 00:00:00 2001 From: Andy Schwartzmeyer Date: Tue, 24 May 2016 14:41:05 -0700 Subject: [PATCH 3/8] Return path to built package in Start-PSBuild For Windows only right now. --- build.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.psm1 b/build.psm1 index d85967af9..512ae18af 100644 --- a/build.psm1 +++ b/build.psm1 @@ -433,8 +433,7 @@ Built upon .NET Core, it is also a C# REPL. Write-Verbose "Packaging $Source" if ($IsWindows) { - Create-MSIPackage -ProductSourcePath $Source -ProductVersion $Version -Verbose - return + return Create-MSIPackage -ProductSourcePath $Source -ProductVersion $Version -Verbose } if (-not (Get-Command "fpm" -ErrorAction SilentlyContinue)) { @@ -1009,8 +1008,9 @@ function Create-MSIPackage & $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 + Write-Verbose "You can find the MSI @ $msiLocationPath" + return $msiLocationPath } From c5a81c2e6e5ea8dac5b4e25e124141cf97ab349c Mon Sep 17 00:00:00 2001 From: Andy Schwartzmeyer Date: Tue, 24 May 2016 14:41:23 -0700 Subject: [PATCH 4/8] Guard Remove-Item in Create-MSIPackage --- build.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.psm1 b/build.psm1 index 512ae18af..f18f18d3b 100644 --- a/build.psm1 +++ b/build.psm1 @@ -1002,14 +1002,14 @@ function Create-MSIPackage $wixObjFragmentPath = (Join-path $env:Temp "Fragment.wixobj") $msiLocationPath = Join-Path $pwd "$productVersionWithName.msi" - del $msiLocationPath -Force + Remove-Item -ErrorAction SilentlyContinue $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 + Remove-Item -ErrorAction SilentlyContinue *.wixpdb -Force - del *.wixpdb -Force Write-Verbose "You can find the MSI @ $msiLocationPath" return $msiLocationPath } From 0afc56d5d46bcbd9394e4a33cd6b6d7329a5dd4a Mon Sep 17 00:00:00 2001 From: Andy Schwartzmeyer Date: Tue, 24 May 2016 14:42:21 -0700 Subject: [PATCH 5/8] Ignore executables --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5cce4090f..6dcc0681d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,8 +13,9 @@ dotnet-install.ps1 *.xproj *.xproj.user -# We copy powershell.exe as a content in host dotnet cli projects +# Ignore executables *.exe +*.msi # ignore the version file as it is generated at build time powershell.version From 44d92a297a540682d0e9e1470b31ceb56b9d524c Mon Sep 17 00:00:00 2001 From: Andy Schwartzmeyer Date: Tue, 24 May 2016 14:49:03 -0700 Subject: [PATCH 6/8] Create MSI packages on AppVeyor --- appveyor.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 1e59ed7ce..8bbc05f39 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -65,6 +65,8 @@ on_finish: - ps: | $ErrorActionPreference = 'Stop' try { + # Build package + $package = Start-PSPackage # Creating project artifact $name = git describe $zipFilePath = Join-Path $pwd "$name.zip" @@ -74,6 +76,7 @@ on_finish: [System.IO.Compression.ZipFile]::CreateFromDirectory($env:FullOutput, $zipFileFullPath) $artifacts = @( + $package, $zipFilePath, $zipFileFullPath ) From b1436e991e1a0e93b7679ea47f45c71da41d1e08 Mon Sep 17 00:00:00 2001 From: Andy Schwartzmeyer Date: Tue, 24 May 2016 14:57:05 -0700 Subject: [PATCH 7/8] Remove MMI from Publish-NuGetFeed This project was removed and provided as a package in the windows-build submodule. The artifact uploading to AppVeyor fails because this was not updated. --- build.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/build.psm1 b/build.psm1 index f18f18d3b..786a1016e 100644 --- a/build.psm1 +++ b/build.psm1 @@ -537,7 +537,6 @@ function Publish-NuGetFeed ) @( -'Microsoft.Management.Infrastructure', 'Microsoft.PowerShell.Commands.Management', 'Microsoft.PowerShell.Commands.Utility', 'Microsoft.PowerShell.ConsoleHost', From a6c04a5bd39d4ecace0c3fd7cc5c93c05e9f8a65 Mon Sep 17 00:00:00 2001 From: Andy Schwartzmeyer Date: Tue, 24 May 2016 15:02:24 -0700 Subject: [PATCH 8/8] Redirect WIX native output to Write-Verbose --- build.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.psm1 b/build.psm1 index 786a1016e..a845c91ce 100644 --- a/build.psm1 +++ b/build.psm1 @@ -1003,9 +1003,9 @@ function Create-MSIPackage $msiLocationPath = Join-Path $pwd "$productVersionWithName.msi" Remove-Item -ErrorAction SilentlyContinue $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 + & $wixHeatExePath dir $ProductSourcePath -dr $productVersionWithName -cg $productVersionWithName -gg -sfrag -srd -scom -sreg -out $wixFragmentPath -var env.ProductSourcePath -v | Write-Verbose + & $wixCandleExePath "$ProductWxsPath" "$wixFragmentPath" -out (Join-Path "$env:Temp" "\\") -arch x64 -v | Write-Verbose + & $wixLightExePath -out "$productVersionWithName.msi" $wixObjProductPath $wixObjFragmentPath -ext WixUIExtension -v | Write-Verbose Remove-Item -ErrorAction SilentlyContinue *.wixpdb -Force