8000 fix MSI creation errors, and capture wixpdb for later patch creation … · PowerShell/PowerShell@22b1f11 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22b1f11

Browse files
committed
fix MSI creation errors, and capture wixpdb for later patch creation (#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 # Conflicts: # assets/Product.wxs
1 parent 579be2e commit 22b1f11

File tree

5 files changed

+74
-18
lines changed

5 files changed

+74
-18
lines changed

.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: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
<!-- UpgradeCode GUID MUST REMAIN SAME THROUGHOUT ALL VERSIONS, otherwise, updates won't occur. -->
1010
<?if $(sys.BUILDARCH)=x64?>
1111
<?define UpgradeCode = "31ab5147-9a97-4452-8443-d9709f0516e1" ?>
12+
<?define ProductSemanticVersionWithNameAndOptionalArchitecture = "$(var.ProductName) $(env.ProductSemanticVersion)"?>
1213
<?else?>
1314
<?define UpgradeCode = "1d00683b-0f84-4db8-a64f-2f98ad42fe06" ?>
15+
<?define ProductSemanticVersionWithNameAndOptionalArchitecture = "$(var.ProductName) $(env.ProductSemanticVersion) ($(sys.BUILDARCH))"?>
1416
<?endif?>
1517
<?define ProductVersion = "$(env.ProductVersion)" ?>
1618
<?define ProductSemanticVersion = "$(env.ProductSemanticVersion)" ?>
@@ -119,20 +121,25 @@
119121
<RegistryValue Type="string" Value="[$(var.ProductVersionWithName)]pwsh.exe"/>
120122
</RegistryKey>
121123
</Component>
122-
<!-- add ourselvs to %PATH% so pwsh.exe can be started from Windows PowerShell or cmd.exe -->
123-
<Component Id="SetPath" Guid="{9dbb7763-7baf-48e7-b025-3bdedcb0632f}">
124+
<!-- add ourselves to %PATH% so pwsh.exe can be started from Windows PowerShell or cmd.exe -->
125+
<Component Id="SetPath" Guid="{9dbb7763-7baf-48e7-b025-3bdedcb0632f}" KeyPath="yes">
124126
<Environment Id="PATH" Action="set" Name="PATH" Part="last" Permanent="no" System="yes" Value="[$(var.ProductVersionWithName)]"/>
125127
</Component>
126128
</Directory>
127129
</Directory>
128130
</Directory>
129131
<Directory Id="ProgramMenuFolder">
130-
<Directory Id="ApplicationProgramsFolder" Name="$(var.ProductSemanticVersionWithName)">
132+
<Directory Id="ApplicationProgramsFolder" Name="$(var.ProductName)">
131133
<Component Id="ApplicationProgramsMenuShortcut" Guid="{A77507A7-F970-4618-AC30-20AFE36EE2EB}">
132-
<Shortcut Id="PowerShell_ProgramsMenuShortcut" Name="$(var.ProductSemanticVersionWithName)" Description="$(var.ProductSemanticVersionWithName)" Target="[$(var.ProductVersionWithName)]pwsh.exe" WorkingDirectory="$(var.ProductVersionWithName)"
133-
Icon = "PowerShellExe.ico" />
134+
<Shortcut Id="PowerShell_ProgramsMenuShortcut"
135+
Name="$(var.ProductSemanticVersionWithNameAndOptionalArchitecture)"
136+
Description="$(var.ProductSemanticVersionWithNameAndOptionalArchitecture)"
137+
Target="[$(var.ProductVersionWithName)]pwsh.exe"
138+
WorkingDirectory="$(var.ProductVersionWithName)"
139+
Icon = "PowerShellExe.ico" />
134140
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
135-
<RegistryValue Root="HKLM" Key="Software\Microsoft\$(var.ProductSemanticVersionWithName)\ProgramsMenuShortcut" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
141+
<!-- HKMU is HKLM when installing perMachine and HKCU when installing perUser-->
142+
<RegistryValue Root="HKMU" Key="Software\Microsoft\$(var.ProductSemanticVersionWithNameAndOptionalArchitecture)\ProgramsMenuShortcut" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
136143
</Component>
137144
</Directory>
138145
</Directory>

build.psm1

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

20102010
# this function wraps native command Execution
20112011
# for more information, read https://mnaoumov.wordpress.com/2015/01/11/execution-of-external-commands-in-powershell-done-right/
2012-
function script:Start-NativeExecution([scriptblock]$sb, [switch]$IgnoreExitcode)
2012+
function script:Start-NativeExecution
20132013
{
2014+
param(
2015+
[scriptblock]$sb,
2016+
[switch]$IgnoreExitcode,
2017+
[switch]$VerboseOutputOnError
2018+
)
20142019
$backupEAP = $script:ErrorActionPreference
20152020
$script:ErrorActionPreference = "Continue"
20162021
try {
2017-
& $sb
2022+
if($VerboseOutputOnError.IsPresent)
2023+
{
2024+
$output = & $sb
2025+
}
2026+
else
2027+
{
2028+
& $sb
2029+
}
2030+
20182031
# note, if $sb doesn't have a native invocation, $LASTEXITCODE will
20192032
# point to the obsolete value
20202033
if ($LASTEXITCODE -ne 0 -and -not $IgnoreExitcode) {
2034+
if($VerboseOutputOnError.IsPresent -and $output)
2035+
{
2036+
$output | Out-String | Write-Verbose -Verbose
2037+
}
2038+
2039+
# Get caller location for easier debugging
2040+
$caller = Get-PSCallStack -ErrorAction SilentlyContinue
2041+
if($caller)
2042+
{
2043+
$callerLocationParts = $caller[1].Location -split ":\s*line\s*"
2044+
$callerFile = $callerLocationParts[0]
2045+
$callerLine = $callerLocationParts[1]
2046+
2047+
$errorMessage = "Execution of {$sb} by ${callerFile}: line $callerLine failed with exit code $LASTEXITCODE"
2048+
2049+
if ($null -ne $env:CI)
2050+
{
2051+
Add-AppveyorCompilationMessage $errorMessage -Category Error -FileName $callerFile -Line $callerLine
2052+
}
2053+
2054+
throw $errorMessage
2055+
}
20212056
throw "Execution of {$sb} failed with exit code $LASTEXITCODE"
20222057
}
20232058
} finally {

tools/packaging/packaging.psm1

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

1543+
# cleanup any garbage on the system
1544+
Remove-Item -ErrorAction SilentlyContinue $wixFragmentPath -Force
1545+
Remove-Item -ErrorAction SilentlyContinue $wixObjProductPath -Force
1546+
Remove-Item -ErrorAction SilentlyContinue $wixObjFragmentPath -Force
1547+
15431548
$packageName = $productSemanticVersionWithName
15441549
if ($ProductNameSuffix) {
15451550
$packageName += "-$ProductNameSuffix"
15461551
}
15471552
$msiLocationPath = Join-Path $pwd "$packageName.msi"
1553+
$msiPdbLocationPath = Join-Path $pwd "$packageName.wixpdb"
15481554

15491555
if(!$Force.IsPresent -and (Test-Path -Path $msiLocationPath))
15501556
{
15511557
Write-Error -Message "Package already exists, use -Force to overwrite, path: $msiLocationPath" -ErrorAction Stop
15521558
}
15531559

1554-
$WiXHeatLog = & $wixHeatExePath dir $ProductSourcePath -dr $productVersionWithName -cg $productVersionWithName -gg -sfrag -srd -scom -sreg -out $wixFragmentPath -var env.ProductSourcePath -v
1555-
$WiXCandleLog = & $wixCandleExePath "$ProductWxsPath" "$wixFragmentPath" -out (Join-Path "$env:Temp" "\\") -ext WixUIExtension -ext WixUtilExtension -arch $ProductTargetArchitecture -v
1556-
$WiXLightLog = & $wixLightExePath -out $msiLocationPath $wixObjProductPath $wixObjFragmentPath -ext WixUIExtension -ext WixUtilExtension -dWixUILicenseRtf="$LicenseFilePath" -v
1560+
log "running heat..."
1561+
Start-NativeExecution -VerboseOutputOnError { & $wixHeatExePath dir $ProductSourcePath -dr $productVersionWithName -cg $productVersionWithName -gg -sfrag -srd -scom -sreg -out $wixFragmentPath -var env.ProductSourcePath -v}
1562+
1563+
log "running candle..."
1564+
Start-NativeExecution -VerboseOutputOnError { & $wixCandleExePath "$ProductWxsPath" "$wixFragmentPath" -out (Join-Path "$env:Temp" "\\") -ext WixUIExtension -ext WixUtilExtension -arch $ProductTargetArchitecture -v}
1565+
1566+
log "running light..."
1567+
# suppress ICE61, because we allow same version upgrades
1568+
# suppress ICE57, this suppresses an error caused by our shortcut not being installed per user
1569+
Start-NativeExecution -VerboseOutputOnError {& $wixLightExePath -sice:ICE61 -sice:ICE57 -out $msiLocationPath -pdbout $msiPdbLocationPath $wixObjProductPath $wixObjFragmentPath -ext WixUIExtension -ext WixUtilExtension -dWixUILicenseRtf="$LicenseFilePath"}
15571570

1558-
Remove-Item -ErrorAction SilentlyContinue *.wixpdb -Force
15591571
Remove-Item -ErrorAction SilentlyContinue $wixFragmentPath -Force
15601572
Remove-Item -ErrorAction SilentlyContinue $wixObjProductPath -Force
15611573
Remove-Item -ErrorAction SilentlyContinue $wixObjFragmentPath -Force
15621574

1563-
if (Test-Path $msiLocationPath)
1575+
if ((Test-Path $msiLocationPath) -and (Test-Path $msiPdbLocationPath))
15641576
{
1577+
Write-Verbose "You can find the WixPdb @ $msiPdbLocationPath" -Verbose
15651578
Write-Verbose "You can find the MSI @ $msiLocationPath" -Verbose
1566-
$msiLocationPath
1579+
[pscustomobject]@{
1580+
msi=$msiLocationPath
1581+
wixpdb=$msiPdbLocationPath
1582+
}
15671583
}
15681584
else
15691585
{
1570-
$WiXHeatLog | Out-String | Write-Verbose -Verbose
1571-
$WiXCandleLog | Out-String | Write-Verbose -Verbose
1572-
$WiXLightLog | Out-String | Write-Verbose -Verbose
15731586
$errorMessage = "Failed to create $msiLocationPath"
15741587
if ($null -ne $env:CI)
15751588
{

tools/releaseBuild/Images/microsoft_powershell_windowsservercore/PowerShellPackage.ps1

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

104104
Write-Verbose "Exporting packages ..." -verbose
105105

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

0 commit comments

Comments
 (0)
0