Kaden.Goodell
Kaden.Goodell

Reputation: 172

Rename Existing Folder using Wix

Our applications installs in a offline network that we generally don't have access to. It is also a high-availability application. We need our old application folder to still be available for use by our user, so we would like to rename the current application folder before installing the new one. That way, if we have some bugs that are no-go, we need them to be able to quickly revert to the old program.

Is this possible with Wix?

Also, we know it's not ideal, but it's what we have, so please just answer the question instead of saying "don't do that".

Upvotes: 1

Views: 382

Answers (1)

ba-a-aton
ba-a-aton

Reputation: 557

Just create Custom action that will start before CostFinalize and move your folder. For example:

<InstallExecuteSequence>
     <Custom Action="RenameFolder"
             Before="CostFinalize"/>
</InstallExecuteSequence>

<CustomAction Id="RenameFolderCustomAction" BinaryKey="YourCustomActionDll" DllEntry="RenameFolderMethod" Execute="immediate" Impersonate="no" Return="check" />

And Your custom action will look like:

[CustomAction]
public static ActionResult RenameFolderMethod(Session session)
{
    session.Log("Begin RenameFolderMethod");
    Directory.Move(source, destination);
    return ActionResult.Success;
}

Also, you'll need to add custom action that will copy it back in case of error or cancel. For this purpose you can use OnExit custom action.

<InstallExecuteSequence>
     <Custom Action="RenameFolder" Before="CostFinalize"/>
    
     <Custom Action="InstallationFailed" OnExit="cancel" />
     <Custom Action="InstallationFailed" OnExit="error" />
</InstallExecuteSequence>

<CustomAction Id="InstallationFailed" BinaryKey="YourCustomActionDll" DllEntry="InstallationFailedMethod" Execute="immediate" Impersonate="no" Return="check" />

And action will be the same, just with reversed parameters:

[CustomAction]
public static ActionResult InstallationFailedMethod(Session session)
{
    session.Log("Begin InstallationFailedMethod");
    Directory.Move(destination, source);//move it back
    return ActionResult.Success;
}

Also you can use properties to store source and destination paths. And you can even define them while running your msi if needed.

How to add custom actions in general

Upvotes: 2

Related Questions