Wix/MSI卸载VSTO加载项初始失败,恢复正常后求故障原因及解决办法
Let me break down your issues based on my hands-on experience with WiX and VSTO deployments:
1. Initial Uninstallation Failure: Causes & Fixes
Possible Root Causes
- Locked Office Processes: VSTO add-ins are deeply tied to Office apps (Word, Excel, Outlook, etc.). If any Office process was running during your first uninstall attempt, it would lock the add-in's registry keys and installation files. Windows Installer often fails silently here instead of throwing a clear error message.
- Misconfigured Registry Tracking: VSTO relies on specific registry entries (typically under
HKCU\Software\Microsoft\Office\[AppName]\Addins\[YourAddinID]) to show up in the Office menu. If your WiX project didn't mark these registry keys asKeyPathor didn't link them properly to components, the MSI wouldn't track them for automatic removal. - Corrupted MSI Cache: Sometimes the Windows Installer cache for your product gets messed up during the first install—maybe from an interrupted setup or permission glitches. This makes the MSI incorrectly think some components are already uninstalled when they're still present.
Practical Fixes
- Force Close Office Processes Before Uninstall: Add a custom action in WiX to detect running Office processes and prompt users to close them, or terminate them gracefully with
taskkill. Here's a quick snippet to add to your WiX project:<CustomAction Id="KillOfficeProcesses" Execute="immediate" Impersonate="yes" Command="taskkill /f /im WINWORD.EXE /im EXCEL.EXE /im OUTLOOK.EXE" /> <InstallExecuteSequence> <Custom Action="KillOfficeProcesses" Before="InstallValidate" /> </InstallExecuteSequence> - Fix Registry Key Setup: Ensure every VSTO-related registry entry in WiX is part of a component with
KeyPath="yes", so the MSI tracks it for removal. Example:<Component Id="AddinRegistry" Guid="YOUR-UNIQUE-GUID-HERE" KeyPath="yes"> <RegistryValue Root="HKCU" Key="Software\Microsoft\Office\Word\Addins\YourAddIn" Name="Description" Value="Your VSTO Add-in" Type="string" /> <RegistryValue Root="HKCU" Key="Software\Microsoft\Office\Word\Addins\YourAddIn" Name="FriendlyName" Value="Your Add-in" Type="string" /> <!-- Add other required VSTO registry values here --> </Component> - Generate and Analyze MSI Logs: Run the uninstall with logging enabled to pinpoint the exact failure:
Look for lines starting withmsiexec /x {YourProductCode} /l*v uninstall.logERRORorWARNING—they'll tell you which components or registry keys couldn't be removed.
2. Why Manual Uninstall + Reinstall Fixed the Issue
When you uninstall via Windows' "Add or Remove Programs", Windows Installer does a full, forced cleanup of the product's cached state and residual components. It wipes out any partial corruption from the first install and removes all leftover registry keys/files that the initial MSI uninstall missed.
When you reinstall after this manual cleanup, the MSI starts with a completely fresh slate: all components are registered correctly, there are no locked processes interfering, and the Windows Installer cache is properly updated. This means the subsequent uninstall can execute all cleanup logic as intended without any prior corruption or locks blocking it.
内容的提问来源于stack exchange,提问作者nam




