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