Skip to content

Commit 49ec403

Browse files
authored
fix MSI creation errors, and capture wixpdb for later patch creation (PowerShell#6221)
- add `wixpdb` output when creating `MSI` package - capture `wixpdb` in official build - clean up anything left behind from previous MSI builds before starting MSI build to prevent using dirty files. - make sure MSI creation fails if there is an error - ignore `.wixpdb` files in git - Add functionality to `Start-NativeExecution` to - only display output if there is an error - log caller information - WXS validation error fixes - Remove unused `ExitDialog` to fix ICE82 - Add KeyPath to `SetPath` to fix ICE18 - Use `HKMU` which translates to `HKLM` to runtime to fix various validation errors about creating the shortcut - Suppress Validation errors - suppress ICE61, which is about same version upgrades being allowed - suppress ICE57, caused by the shortcut not being installed per user
1 parent a53547c commit 49ec403

5 files changed

Lines changed: 70 additions & 18 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dotnet-uninstall-debian-packages.sh
3535
# Ignore binaries and symbols
3636
*.pdb
3737
*.dll
38+
*.wixpdb
3839

3940
# Ignore packages
4041
*.deb

assets/Product.wxs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
</RegistryKey>
158158
</Component>
159159
<!-- add ourselves to %PATH% so pwsh.exe can be started from Windows PowerShell or cmd.exe -->
160-
<Component Id="SetPath" Guid="{9dbb7763-7baf-48e7-b025-3bdedcb0632f}">
160+
<Component Id="SetPath" Guid="{9dbb7763-7baf-48e7-b025-3bdedcb0632f}" KeyPath="yes">
161161
<Environment Id="PATH" Action="set" Name="PATH" Part="last" Permanent="no" System="yes" Value="[$(var.ProductVersionWithName)]"/>
162162
</Component>
163163
<!-- Explorer context menu with 2 submenus to open PowerShell normally or as an Administator.
@@ -211,10 +211,15 @@
211211
<Directory Id="ProgramMenuFolder">
212212
<Directory Id="ApplicationProgramsFolder" Name="$(var.ProductName)">
213213
<Component Id="ApplicationProgramsMenuShortcut" Guid="{A77507A7-F970-4618-AC30-20AFE36EE2EB}">
214-
<Shortcut Id="PowerShell_ProgramsMenuShortcut" Name="$(var.ProductSemanticVersionWithNameAndOptionalArchitecture)" Description="$(var.ProductSemanticVersionWithNameAndOptionalArchitecture)" Target="[$(var.ProductVersionWithName)]pwsh.exe" WorkingDirectory="$(var.ProductVersionWithName)"
215-
Icon = "PowerShellExe.ico" />
214+
<Shortcut Id="PowerShell_ProgramsMenuShortcut"
215+
Name="$(var.ProductSemanticVersionWithNameAndOptionalArchitecture)"
216+
Description="$(var.ProductSemanticVersionWithNameAndOptionalArchitecture)"
217+
Target="[$(var.ProductVersionWithName)]pwsh.exe"
218+
WorkingDirectory="$(var.ProductVersionWithName)"
219+
Icon = "PowerShellExe.ico" />
216220
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
217-
<RegistryValue Root="HKLM" Key="Software\Microsoft\$(var.ProductSemanticVersionWithNameAndOptionalArchitecture)\ProgramsMenuShortcut" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
221+
<!-- HKMU is HKLM when installing perMachine and HKCU when installing perUser-->
222+
<RegistryValue Root="HKMU" Key="Software\Microsoft\$(var.ProductSemanticVersionWithNameAndOptionalArchitecture)\ProgramsMenuShortcut" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
218223
</Component>
219224
</Directory>
220225
</Directory>
@@ -289,8 +294,6 @@
289294
<Publish Dialog="BrowseDlg" Control="OK" Event="DoAction" Value="WixUIValidatePath" Order="3">1</Publish>
290295
<Publish Dialog="BrowseDlg" Control="OK" Event="SpawnDialog" Value="InvalidDirDlg" Order="4"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
291296

292-
<Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>
293-
294297
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="LicenseAgreementDlg">NOT Installed</Publish>
295298
<Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">Installed AND PATCH</Publish>
296299

build.psm1

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,15 +2027,50 @@ function script:precheck([string]$command, [string]$missedMessage) {
20272027

20282028
# this function wraps native command Execution
20292029
# for more information, read https://mnaoumov.wordpress.com/2015/01/11/execution-of-external-commands-in-powershell-done-right/
2030-
function script:Start-NativeExecution([scriptblock]$sb, [switch]$IgnoreExitcode)
2030+
function script:Start-NativeExecution
20312031
{
2032+
param(
2033+
[scriptblock]$sb,
2034+
[switch]$IgnoreExitcode,
2035+
[switch]$VerboseOutputOnError
2036+
)
20322037
$backupEAP = $script:ErrorActionPreference
20332038
$script:ErrorActionPreference = "Continue"
20342039
try {
2035-
& $sb
2040+
if($VerboseOutputOnError.IsPresent)
2041+
{
2042+
$output = & $sb
2043+
}
2044+
else
2045+
{
2046+
& $sb
2047+
}
2048+
20362049
# note, if $sb doesn't have a native invocation, $LASTEXITCODE will
20372050
# point to the obsolete value
20382051
if ($LASTEXITCODE -ne 0 -and -not $IgnoreExitcode) {
2052+
if($VerboseOutputOnError.IsPresent -and $output)
2053+
{
2054+
$output | Out-String | Write-Verbose -Verbose
2055+
}
2056+
2057+
# Get caller location for easier debugging
2058+
$caller = Get-PSCallStack -ErrorAction SilentlyContinue
2059+
if($caller)
2060+
{
2061+
$callerLocationParts = $caller[1].Location -split ":\s*line\s*"
2062+
$callerFile = $callerLocationParts[0]
2063+
$callerLine = $callerLocationParts[1]
2064+
2065+
$errorMessage = "Execution of {$sb} by ${callerFile}: line $callerLine failed with exit code $LASTEXITCODE"
2066+
2067+
if ($null -ne $env:CI)
2068+
{
2069+
Add-AppveyorCompilationMessage $errorMessage -Category Error -FileName $callerFile -Line $callerLine
2070+
}
2071+
2072+
throw $errorMessage
2073+
}
20392074
throw "Execution of {$sb} failed with exit code $LASTEXITCODE"
20402075
}
20412076
} finally {

tools/packaging/packaging.psm1

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,36 +2120,49 @@ function New-MSIPackage
21202120
$wixObjProductPath = Join-Path $env:Temp "Product.wixobj"
21212121
$wixObjFragmentPath = Join-Path $env:Temp "Fragment.wixobj"
21222122

2123+
# cleanup any garbage on the system
2124+
Remove-Item -ErrorAction SilentlyContinue $wixFragmentPath -Force
2125+
Remove-Item -ErrorAction SilentlyContinue $wixObjProductPath -Force
2126+
Remove-Item -ErrorAction SilentlyContinue $wixObjFragmentPath -Force
2127+
21232128
$packageName = $productSemanticVersionWithName
21242129
if ($ProductNameSuffix) {
21252130
$packageName += "-$ProductNameSuffix"
21262131
}
21272132
$msiLocationPath = Join-Path $pwd "$packageName.msi"
2133+
$msiPdbLocationPath = Join-Path $pwd "$packageName.wixpdb"
21282134

21292135
if(!$Force.IsPresent -and (Test-Path -Path $msiLocationPath))
21302136
{
21312137
Write-Error -Message "Package already exists, use -Force to overwrite, path: $msiLocationPath" -ErrorAction Stop
21322138
}
21332139

2134-
$WiXHeatLog = & $wixHeatExePath dir $ProductSourcePath -dr $productVersionWithName -cg $productVersionWithName -gg -sfrag -srd -scom -sreg -out $wixFragmentPath -var env.ProductSourcePath -v
2135-
$WiXCandleLog = & $wixCandleExePath "$ProductWxsPath" "$wixFragmentPath" -out (Join-Path "$env:Temp" "\\") -ext WixUIExtension -ext WixUtilExtension -arch $ProductTargetArchitecture -v
2136-
$WiXLightLog = & $wixLightExePath -out $msiLocationPath $wixObjProductPath $wixObjFragmentPath -ext WixUIExtension -ext WixUtilExtension -dWixUILicenseRtf="$LicenseFilePath" -v
2140+
log "running heat..."
2141+
Start-NativeExecution -VerboseOutputOnError { & $wixHeatExePath dir $ProductSourcePath -dr $productVersionWithName -cg $productVersionWithName -gg -sfrag -srd -scom -sreg -out $wixFragmentPath -var env.ProductSourcePath -v}
2142+
2143+
log "running candle..."
2144+
Start-NativeExecution -VerboseOutputOnError { & $wixCandleExePath "$ProductWxsPath" "$wixFragmentPath" -out (Join-Path "$env:Temp" "\\") -ext WixUIExtension -ext WixUtilExtension -arch $ProductTargetArchitecture -v}
2145+
2146+
log "running light..."
2147+
# suppress ICE61, because we allow same version upgrades
2148+
# suppress ICE57, this suppresses an error caused by our shortcut not being installed per user
2149+
Start-NativeExecution -VerboseOutputOnError {& $wixLightExePath -sice:ICE61 -sice:ICE57 -out $msiLocationPath -pdbout $msiPdbLocationPath $wixObjProductPath $wixObjFragmentPath -ext WixUIExtension -ext WixUtilExtension -dWixUILicenseRtf="$LicenseFilePath"}
21372150

2138-
Remove-Item -ErrorAction SilentlyContinue *.wixpdb -Force
21392151
Remove-Item -ErrorAction SilentlyContinue $wixFragmentPath -Force
21402152
Remove-Item -ErrorAction SilentlyContinue $wixObjProductPath -Force
21412153
Remove-Item -ErrorAction SilentlyContinue $wixObjFragmentPath -Force
21422154

2143-
if (Test-Path $msiLocationPath)
2155+
if ((Test-Path $msiLocationPath) -and (Test-Path $msiPdbLocationPath))
21442156
{
2157+
Write-Verbose "You can find the WixPdb @ $msiPdbLocationPath" -Verbose
21452158
Write-Verbose "You can find the MSI @ $msiLocationPath" -Verbose
2146-
$msiLocationPath
2159+
[pscustomobject]@{
2160+
msi=$msiLocationPath
2161+
wixpdb=$msiPdbLocationPath
2162+
}
21472163
}
21482164
else
21492165
{
2150-
$WiXHeatLog | Out-String | Write-Verbose -Verbose
2151-
$WiXCandleLog | Out-String | Write-Verbose -Verbose
2152-
$WiXLightLog | Out-String | Write-Verbose -Verbose
21532166
$errorMessage = "Failed to create $msiLocationPath"
21542167
if ($null -ne $env:CI)
21552168
{

tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ try{
105105

106106
Write-Verbose "Exporting packages ..." -verbose
107107

108-
Get-ChildItem $location\*.msi,$location\*.zip | ForEach-Object {
108+
Get-ChildItem $location\*.msi,$location\*.zip,$location\*.wixpdb | ForEach-Object {
109109
$file = $_.FullName
110110
Write-Verbose "Copying $file to $destination" -verbose
111111
Copy-Item -Path $file -Destination "$destination\" -Force

0 commit comments

Comments
 (0)