WiX custom action with DTF… quite confused

牧云@^-^@ 提交于 2019-12-12 10:25:00

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/2953366/wix-custom-action-with-dtf-quite-confused

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!