Merge pull request #1032 from PowerShell/RaghuS-MSIPackageBranch

Capability to generate Windows MSI packages
This commit is contained in:
Raghu Shantha [MSFT] 2016-05-24 15:55:18 -07:00
commit 2c15664679
4 changed files with 169 additions and 15 deletions

3
.gitignore vendored
View file

@ -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

81
Product.wxs Normal file
View file

@ -0,0 +1,81 @@
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<?define Win7SP1OrLater = "(VersionNT = 601 AND ServicePackLevel >= 1) OR VersionNT > 601" ?>
<!-- The URL for add/remove programs -->
<!-- TBD:Point to the actual release -->
<?define InfoURL="https://github.com/PowerShell/PowerShell" ?>
<?define ProductName = "$(env.ProductName)" ?>
<?define ProductGuid = "$(env.ProductGuid)" ?>
<?define ProductVersion = "$(env.ProductVersion)" ?>
<?define ProductVersionWithName = "$(var.ProductName)_$(var.ProductVersion)"?>
<!-- Generate Your Own GUID for both ID and UpgradeCode attributes. -->
<!-- Note: UpgradeCode GUID MUST REMAIN SAME THROUGHOUT ALL VERSIONS -->
<!-- Otherwise, updates wont occur -->
<Product Id="$(var.ProductGuid)" Name="$(var.ProductVersionWithName)" Language="1033" Version="0.1.0.0" Manufacturer="Microsoft Corporation" UpgradeCode="{f7ba3e58-0be8-443b-ac91-f99dd1e7bd3b}">
<!-- Properties About The Package -->
<Package Id="*" Keywords="Installer" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Description="OpenPowerShell package" Comments="OpenPowerShell" />
<!-- Set properties for add/remove programs -->
<Property Id="ARPHELPLINK" Value="$(var.InfoURL)" />
<!-- Prerequisites -->
<Condition Message="Supported only on Win7SP1 or later"><![CDATA[ Installed OR $(var.Win7SP1OrLater) ]]></Condition>
<!-- Information About When Older Versions Are Trying To Be Installed-->
<MajorUpgrade DowngradeErrorMessage="A newer version of OpenPowerShell is already installed." />
<!-- Embed Cabinet Files in Product-->
<MediaTemplate EmbedCab="yes" />
<!-- In Your Wix Setup Project, Add A Reference To WixUIExtension.dll -->
<!-- This is a minimal User Interface. In fact, it only displays a license -->
<!-- acceptance dialog. It doesnt do anything else except provide -->
<!-- basic status during installation. -->
<UIRef Id="WixUI_Minimal" />
<!-- Features are mandatory. Need At Least One. -->
<Feature Id="ProductFeature" Title="OpenPowerShell" Level="1">
<ComponentGroupRef Id="$(var.ProductVersionWithName)"/>
<ComponentRef Id="ProductVersionFolder"/>
<ComponentRef Id="ApplicationProgramsMenuShortcut"/>
</Feature>
<!--We need to show EULA, but not provide option to customize download location-->
<Property Id="WixUI_Minimal" Value="$(var.ProductVersionWithName)" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles64Folder">
<Directory Id="INSTALLFOLDER" Name="OpenPowerShell">
<Directory Id="$(var.ProductVersionWithName)" Name="$(var.ProductVersion)">
<Component Id="ProductVersionFolder" Guid="{e1a7f05e-0cd6-4227-80a8-e4fb311f045c}">
<CreateFolder/>
</Component>
</Directory>
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="$(var.ProductVersionWithName)">
<Component Id="ApplicationProgramsMenuShortcut" Guid="{A77507A7-F970-4618-AC30-20AFE36EE2EB}">
<Shortcut Id="OpenPowerShell_ProgramsMenuShortcut"
Name="$(var.ProductVersionWithName)"
Description="$(var.ProductVersionWithName)"
Target="[$(var.ProductVersionWithName)]PowerShell.exe"
WorkingDirectory="$(var.ProductVersionWithName)"/>
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
<RegistryValue Root="HKCU"
Key="Software\Microsoft\$(var.ProductVersionWithName)\ProgramsMenuShortcut"
Name="installed"
Type="integer"
Value="1" KeyPath="yes"/>
</Component>
</Directory>
</Directory>
</Directory>
</Product>
</Wix>

View file

@ -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
)

View file

@ -424,17 +424,22 @@ 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) {
return Create-MSIPackage -ProductSourcePath $Source -ProductVersion $Version -Verbose
}
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 +461,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 +477,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" }
@ -538,7 +537,6 @@ function Publish-NuGetFeed
)
@(
'Microsoft.Management.Infrastructure',
'Microsoft.PowerShell.Commands.Management',
'Microsoft.PowerShell.Commands.Utility',
'Microsoft.PowerShell.ConsoleHost',
@ -944,3 +942,74 @@ 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"
# 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"
Remove-Item -ErrorAction SilentlyContinue $msiLocationPath -Force
& $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
Write-Verbose "You can find the MSI @ $msiLocationPath"
return $msiLocationPath
}