Welcome to MSDN Blogs Sign in | Join | Help

WiX: Removing Files with Patches

I've had numerous people ask me how to remove a file using a patch. As I say below again, this should be done carefully.
 
Background
If a file is present in a Baseline package then removed in the Upgrade package, it is not trivial to get the installer to remove the file in a way that uninstalling the patch will put it back.
 
Important!!! MUST READ
 
Before removing a file you need to make sure you have no other options. The only time you should remove a file using a patch is when the mere presence of the file causes problems. Consider removing references to the file from files that use it or patching it to be an "empty" file. Removing a file should be a last resort.
 
For shared files, removing a file with a patch could mean breaking any other product using that file. The removal of the file does not take reference counting into account when determining to remove a file. It will be removed if you tell it to be removed. Make sure you consider everything that uses or could use the file before removing it.
 

If a file must be removed by a patch there are a few options:

If the file is not a the keypath of its component:

- Remove the file from the component
- Add a RemoveFile entry to the component.

If the file is the keypath if its component:

If the file is the keypath, it means this file is the identity of the component. In this case the entire component must be removed. You cannot simply remove a component using a patch. If you do, you have to remove the entire feature which is not usually the desired scenario. If it is, then just remove the feature from your patch.

In order to remove a component without removing its feature you need to convince Windows Installer that the component isnt supposed to be installed but the msi database still needs to know about it. You can achieve this by making the component's condition false. In order to cause a recalcalculation of the component during repair/patch you also need to mark the component as transitive. The side-affect of this is that when the patch is uninstalled, the file is not put back on the machine. This is because when the patch is removed, the component is no longer transitive and its condition is not reevaluated. You can solve this by shipping two patches. One that marks the component as transitive and a second that makes the component's condition false.

Example:

<Component Id="Foo" Transitive="yes" ... >
    <Condition>FALSE</Condition>
      ...
</Component>

Notes and considerations:

In any case, uninstalling the patch may prompt for source if the file that needs to be put back is not available to the installer.

If building 2 patches for the transitive solution, you cannot base the two patches off of the same build because both changes are made to a single component which is the smallest level at which patches can be filtered. 

Published Tuesday, May 19, 2009 11:17 PM by Petermarcu
Filed under: , , , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# WiX: Removing Files with Patches | ASP NET Hosting

Wednesday, May 20, 2009 3:13 AM by WiX: Removing Files with Patches | ASP NET Hosting

# re: WiX: Removing Files with Patches

Hi, Peter:

Thank you firstly!

and I test as you said, but some exception.

first, in the baseline wxs file:

<Fragment>

       <DirectoryRef Id="SampleProductFolder">

           <Component Id="SampleComponent" Guid="C28843DA-EF08-41CC-BA75-D2B99D8A1983" DiskId="1">

               <File Id="SampleFile" Name="Sample.txt" Source=".\$(var.Version)\Sample.txt" />

               <File Id="classFile"  Name="loadtest.class" Source=".\$(var.Version)\loadtest.class" />

               <File Id="SampleFileDel1" Name="SampleDel1.txt" KeyPath="no" Source=".\$(var.Version)\SampleDel1.txt" />

           </Component>

       </DirectoryRef>

   </Fragment>

Now, I want remove the SampleDel1.txt, the wxs is changed into:

<Fragment>

       <DirectoryRef Id="SampleProductFolder">

           <Component Id="SampleComponent" Guid="C28843DA-EF08-41CC-BA75-D2B99D8A1983" DiskId="1">

               <File Id="SampleFile" Name="Sample.txt" Source=".\$(var.Version)\Sample.txt" />

               <File Id="classFile"  Name="loadtest.class" Source=".\$(var.Version)\loadtest.class" />

               <RemoveFile Id="delSampleFileDel1" Name="SampleDel1.txt" On="install" />  

           </Component>

       </DirectoryRef>

   </Fragment>

Then, candle, light, torch, pyro.

At last I get a warning:

C:\DevelopTools\WIX\WIX3.0\examples\patchexample\product10.wxs(29) : warning PYR

O1095 : File 'SampleFileDel1' was removed from component 'SampleComponent'. Remo

ving a file from a component will not result in the file being removed by a patc

h. You should author a RemoveFile element in your component to remove the file f

rom the installation if you want the file to be removed.

C:\DevelopTools\WIX\WIX3.0\examples\patchexample\patch.wxs(12) : warning PYRO107

9 : The cabinet 'RTM.cab' does not contain any files.  If this installation cont

ains no files, this warning can likely be safely ignored.  Otherwise, please add

files to the cabinet or remove it.

May I get your help to find out the reason?

Wednesday, May 20, 2009 3:46 AM by Bowyer

# re: WiX: Removing Files with Patches

It looks like you are fine on both warnings. You did add a RemoveFile entry in the component and you are not expecting to have any files in the patch so both warnings are ok.

For the first one, that is a bug. It should detect that you did add a RemoveFile entry and not show the warning.

Wednesday, May 20, 2009 4:19 AM by Petermarcu

# re: WiX: Removing Files with Patches

Yes, Peter, you are right. There are just warnings, the patch works normally. Thank you very much!

But when there is only one file (KeyPath file) in the component, it can't work. I am still fighting for this problem. Heh, Heh.

It's dangerous and difficult!

Maybe I will back to disturb you! Thank you again!

Wednesday, May 20, 2009 6:06 AM by Bowyer

# re: WiX: Removing Files with Patches

Hmm, you may need to also add a seperate component which contains the RemoveFile entry rather than putting it in the same component in this case.

Wednesday, May 20, 2009 6:16 AM by Petermarcu

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker