installation - 使用 Wix 重命名现有文件夹
问题描述
我们的应用程序安装在我们通常无法访问的离线网络中。它也是一个高可用性应用程序。我们需要我们的旧应用程序文件夹仍然可供用户使用,因此我们希望在安装新应用程序文件夹之前重命名当前应用程序文件夹。这样,如果我们有一些不可行的错误,我们需要它们能够快速恢复到旧程序。
Wix可以做到这一点吗?
此外,我们知道这并不理想,但这是我们所拥有的,所以请回答问题而不是说“不要那样做”。
解决方案
只需创建将在 CostFinalize 之前开始的自定义操作并移动您的文件夹。例如:
<InstallExecuteSequence>
<Custom Action="RenameFolder"
Before="CostFinalize"/>
</InstallExecuteSequence>
<CustomAction Id="RenameFolderCustomAction" BinaryKey="YourCustomActionDll" DllEntry="RenameFolderMethod" Execute="immediate" Impersonate="no" Return="check" />
您的自定义操作将如下所示:
[CustomAction]
public static ActionResult RenameFolderMethod(Session session)
{
session.Log("Begin RenameFolderMethod");
Directory.Move(source, destination);
return ActionResult.Success;
}
此外,您需要添加自定义操作,以便在出现错误或取消时将其复制回来。为此,您可以使用 OnExit 自定义操作。
<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" />
动作也是一样的,只是参数颠倒了:
[CustomAction]
public static ActionResult InstallationFailedMethod(Session session)
{
session.Log("Begin InstallationFailedMethod");
Directory.Move(destination, source);//move it back
return ActionResult.Success;
}
您还可以使用属性来存储源路径和目标路径。如果需要,您甚至可以在运行 msi时定义它们。
推荐阅读
- c - 带有一个输入的 strcmp 的分段错误
- python - 构造函数重载python
- python - 使用 Python 和 Selenium,我将如何绕过 2 因素身份验证?
- r - 在 macOS Catalina 上为 Jupyter 提供内核时出现 IRkernel::installspec() 错误
- javascript - 最后一个选项卡下一个按钮将其重定向到主页
- game-physics - Godot - 从脚本中获取物理 fps?
- python - Python:为 Pandas Dataframe 中的列表计算 PMF
- caching - 设置关联缓存 - 有多少内存块映射到一组?
- ubuntu - Ubuntu - 使用用户输入的顺序文件命名
- c++ - 当我使用 1000 个键值的数据集时出现分段错误,并且由于某种原因,AVL 旋转不会发生在节点周围