Ensure finalizer only runs when no matching SDK feature bands are installed #14836
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When a user updates an SDK after installing a workload, the workload is expected to remain installed.
Repro Steps
dotnet workload install wasm-tools
dotnet workload list
Expected: wasm-tools should be listed as installed
Actual: No installed workloads are reported.
Fix
The finalizer in the SDK bundle is used to remove optional workloads installed through the CLI when the SDK is removed. When an SDK bundle is upgraded, the new SDK is installed before the previous bundle is removed. No properties are available to distinguish between an uninstall and an uninstall due to a major upgrade and the finalizer ends up removing workloads.
The package chain in the bundle is executed in reverse order when it is uninstalled. During an install, the finalizer will be first in the chain, but skipped due to its install condition. When the bundle is removed, the old SDK toolset MSI is removedbefore the finalizer runs. This allows the finalizer to detect the absence of matching SDK feature bands and remove any remaining workloads.
During an upgrade, the new SDK toolset MSI is present then the finalizer executes, allowing it to detect the presence of an SDK with a feature band matching the SDK being removed. In this case the finalizer will terminate and leave the previously installed workloads installed.
Testing
Manual testing required since we need a build with the fix and another build of the SDK bundle that can be upgraded.