Skip to content

Commit 1109be8

Browse files
committed
Update finalizer
1 parent 7575954 commit 1109be8

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

src/Layout/finalizer/Program.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
using Microsoft.Win32;
66
using Microsoft.Win32.Msi;
77

8-
if (args.Length < 3)
8+
if (args.Length < 4)
99
{
1010
return (int)Error.INVALID_COMMAND_LINE;
1111
}
1212

1313
string logPath = args[0];
1414
string sdkVersion = args[1];
1515
string platform = args[2];
16+
int bundleAction = Convert.ToInt32(args[3]);
1617

1718
using StreamWriter logStream = new StreamWriter(logPath);
1819

@@ -21,8 +22,16 @@
2122
Logger.Log($"{nameof(logPath)}: {logPath}");
2223
Logger.Log($"{nameof(sdkVersion)}: {sdkVersion}");
2324
Logger.Log($"{nameof(platform)}: {platform}");
25+
Logger.Log($"{nameof(bundleAction)}: {bundleAction}");
2426
int exitCode = (int)Error.SUCCESS;
2527

28+
// The finalizer should only run when the parent bundle is being removed if WixBundleAction is set to BOOTSTRAPPER_ACTION_UNINSTALL
29+
// or BOOTSTRAPPER_ACTION_UNSAFE_UNINSTALL.
30+
if (bundleAction < 3 || bundleAction > 4)
31+
{
32+
return exitCode;
33+
}
34+
2635
try
2736
{
2837
// Step 1: Parse and format SDK feature band version

src/Layout/pkg/windows/bundles/sdk/bundle.wxs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -159,31 +159,27 @@
159159
<Chain DisableSystemRestore="yes" ParallelCache="yes">
160160

161161
<!--
162-
The finalizer is not an actual installation package. We "detect" the EXE
163-
based on the action the bundle is performing to ensure it runs the uninstall
164-
command only when the bundle is being removed. The package is always installable because the bundle
165-
will remove the package (execute its UninstallCommand) if it is not installable when then bundle is
166-
being installed.
167-
168-
See https://github.com/orgs/wixtoolset/discussions/9017. We cannot rely on the bundle action since it isn't finalized
169-
until the detect phase completes and therefore not available in a detect condition. We'll need to add explicit install/uninstall commands
170-
to the finalizer.
171-
172-
The finalizer is first in the chain to ensure it executes last during an uninstall. When the
173-
SDK is upgraded, the old SDK will be removed before the finalizer executes. This ensures that the
174-
finalizer detects the new SDK and does nothing because the feature band matches.
175-
176-
For an install+uninstall scenario, because the SDK MSI is removed prior to the finalizer, it will
177-
detect that there are no matching feature bands and then clean up workloads associated with
178-
the feature band.
179-
-->
162+
The finalizer is not an installation package. It's detected based on the bundle's installation state (WixBundleInstalled).
163+
164+
User action | Install | Repair | Modify | Uninstall | Uninstall (Upgrade)
165+
WixBundleInstalled | FALSE | TRUE | TRUE | TRUE | TRUE
166+
WixBundleAction | 6 | 8 | 7 | 4 | 4
167+
Finalizer (Plan) | None | Execute | Execute | Execute | Execute
168+
169+
Setting an InstallCondition will cause Burn to remove the package if it evaluates to FALSE and
170+
the bundle is being installed, repaired, or modified. This breaks upgrades. We cannot use
171+
WixBundleAction in the DetectCondition because it's not finalized until the planning phase completes (after
172+
the detect phase). See https://github.com/orgs/wixtoolset/discussions/9017 for more detail.
173+
174+
The finalizer also takes the bundle action as a parameter to ensure it no-ops, but logs the action. -->
180175
<ExePackage SourceFile="$(FinalizerExeSourceFile)"
181176
Bundle="no"
182177
Cache="keep"
183-
DetectCondition="WixBundleInstalled"
178+
DetectCondition="1=1"
184179
Id="Finalizer"
185-
InstallCondition="WixBundleAction >= 4"
186-
UninstallArguments="&quot;[WixBundleLog_Finalizer]&quot; $(Version) $(TargetArchitecture)"
180+
InstallArguments="&quot;[WixBundleLog_Finalizer]&quot; $(Version) $(TargetArchitecture) [WixBundleAction]"
181+
UninstallArguments="&quot;[WixBundleLog_Finalizer]&quot; $(Version) $(TargetArchitecture) [WixBundleAction]"
182+
RepairArguments="&quot;[WixBundleLog_Finalizer]&quot; $(Version) $(TargetArchitecture) [WixBundleAction]"
187183
Vital="no" />
188184

189185
<!-- .NET Runtime has to be installed before the CLI because of a custom action that depends on dotnet.exe. -->

0 commit comments

Comments
 (0)