views:

186

answers:

1

Okay, I have decided the only way I can do what I want to do with WiX (thanks to an old installer I didn't write that I now have to upgrade) is with some CUSTOM ACTIONS.

Basically, I need to back up a file before the RemoveExistingProducts and restore that file again after RemoveExistingProducts. I think this is what's called a "type 2 custom action."

The sequencing I think I understand, however, what I don't understand is first of all how I pass data to my C# action (the directory the file is in from the WiX) and how to reference my C# (DTF?) action with the Binary and CustomAction tags.

Also, does all this need to be in a tag? All the examples show it that way.

Here is what I have so far in the .WXS file...

<Binary Id="backupSettingsAction.dll" 
            SourceFile="backupSettingsAction.CA.dll"/>
    <CustomAction
              Id="BackupSettingsAction"
              BinaryKey="backupSettingsAction.dll"
              DllEntry="CustomAction" 
              Execute="immediate" />

    <InstallExecuteSequence>
        <Custom Action="backupSettingsAction.dll" Before="InstallInitialize"/>
        <RemoveExistingProducts After="InstallFinalize" />
        <Custom Action="restoreSettingsAction.dll" After="RemoveExistingFiles"/>
    </InstallExecuteSequence>

The file I need to back up is a settings file from the previous install (which needs to remain intact), it is located in the directory:

<Directory Id="CommonAppDataFolder" Name="CommonAppData">
            <Directory Id="CommonAppDataPathways" Name="Pathways" />
        </Directory>

And even has a Component tag for it, though I need to back the file up that exists already:

<Component Id="Settings" Guid="A3513208-4F12-4496-B609-197812B4A953" NeverOverwrite="yes" >
    <File Id="settingsXml" ShortName="SETTINGS.XML" Name="Settings.xml" DiskId="1" Source="\\fileserver\Release\Pathways\Dependencies\Settings\settings.xml" Vital="yes" />
</Component>

And this is referencing the C# file that Visual Studio (2005) created for me:

namespace backupSettingsAction
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult CustomAction1(Session session)
        {
            session.Log("backing up settings file");

            //do I hardcode the directory and name of the file in here, or can I pass them in?

            return ActionResult.Success;
        }
    }
}

Any help is greatly apprecaited. Thank you!

A: 

Can we get back to why you think you need a custom action for a moment?

Depending on the problem you are trying to solve you should be able to do one of two things

1) Put the XML file in it' own component, marked as keyfile and set to permanent.

2) Create a dummy DLL and give it a version of 1.0.0.0. Never increment this DLL's version number in the future. Put the DLL and XML file in a component with the DLL set to keyfile and the component set to permanent.

You should now be able to do major upgrades and persist the contents of the XML file regardless of whether it's ever been modified to include user data or not.

Christopher Painter
Except the problem is with an old installer that I did not write, which wants to delete the XML file on uninstall. Here is the progression that brought me to this point...http://stackoverflow.com/questions/2768701/stuck-on-preserving-config-file-in-wix-major-upgradehttp://stackoverflow.com/questions/2775763/problem-with-wix-major-upgradehttp://stackoverflow.com/questions/2868218/wix-major-upgrade-refuses-to-replace-existing-filehttp://stackoverflow.com/questions/2951355/wix-major-upgrade-need-different-behaviors-for-different-components
Joshua
Ah, I see now. I've had this problem before and what I did was "patch" the old installer to change it's behavior before calling my installer for a major upgrade. That way when RemoveExistingProducts call the old product for uninstall the bad behavior won't occur.
Christopher Painter