Remove file during minor upgrade

2019-01-28 19:18发布

问题:

I have one feature with several components. One components contains dynamic linked files in a directory. When I delete one file in that directory, build the setup, and run the upgrade, no file will be replaced. In the log I found this error:

MSI (s) (5C:D8) [12:28:41:180]: SELMGR: ComponentId '{8F4E8185-5B89-9FC9-9FD5-3200102A0265}' is registered to feature 'MyFeatureName', but is not present in the Component table.  Removal of components from a feature is not supported!
MSI (s) (5C:D8) [12:28:41:180]: SELMGR: Removal of a component from a feature is not supported

How can I remove a dynamic linked file?

回答1:

The book answer is use a major upgrade.

The ultimate MSI hacker's answer is to edit the previous MSI in ORCA to get the exact primary key and GUID values. Author that component statically into your latest ISM and then implement the "puncture component" pattern. This means you set the Revaluate attribute and then give it a condition that always evaluates to false. In this way the new MSI still has the component but it gets removed from the machine.



回答2:

Chris has described the method I normally use to fix such a problem. However, I find that a quicker approach is to rename the parent folder for the dynamically linked files. Just changing from MyFolder to My Folder will work - or any other name for that matter. The reason is that you de-couple the old files from the new ones. You no longer point to the same absolute paths, and MSI reference counting hence removes all old files correctly. And you need a major upgrade for this to work correctly like Chris says.

A very good summary of what is required for a minor upgrade to work (as well as other details): http://www.installsite.org/pages/en/msi/updates.htm

From the above site: "If you remove a file or registry key from a component, you must populate the RemoveFile or RemoveRegistry table respectively to delete the orphaned resource.". This might also work, but I would not use this approach.

Personally I would avoid dynamic file linking altogether. I have never been able to use dynamically linked files without it resulting in a problem. Generally they have been update and patching problems, but also other kinds. It really is not a good feature to use. Rather you should take the opportunity with the folder name change to add all files statically.

You can find more details on MSI component reference counting here: https://stackoverflow.com/a/1422121/129130

So in summary here is what I would do:

  • Create backup of your installation project
  • Delete all dynamically linked files
  • Modify the name of the parent directory that used to hosts dynamically linked files. For example from MyFiles to My Files will do.
  • Re-add all dynamically linked files with static components