如何在自定义操作中使用 VS Installer 类
我发现了数十个问答条目(除了 stackoverflow 中的一个之外)都接近这个问题,但没有告诉我我需要什么。我的安装几乎是简单的:一个 Windows 服务和一个关联的托盘图标应用程序。它们可以与标准 VS 安装项目很好地安装。安装文件后,我需要向用户显示一个对话框,以在服务的 exe.config 文件中设置一些参数。在该对话框中,用户应该能够中止安装。我尝试了两种自定义操作过程的方法,但在回滚安装时都遇到了困难。
方法 1:自定义操作的 exe,在提交时运行。 这种工作。应用程序返回非零退出代码并发生安装回滚。我不喜欢的是:
- 当应用程序退出时(用户选择取消后),安装会显示一条错误消息,指出安装出现问题,用户应联系供应商。由于情况并非如此,我希望有更正确的消息(“用户取消安装”)或根本没有消息。
- 两个项目输出(服务和托盘应用程序)都必须列在所有四个自定义操作部分下,否则我的对话框将不会出现。相反,会出现有关缺少 InstallState 文件的错误,并且安装总是失败。直觉上,这似乎是错误的。
方法 2:安装程序作为自定义操作,在安装或提交时运行。 这对我来说更干净(只有自定义操作中列出的一项),但是让进程回滚比方法 1 更糟糕。似乎我必须在覆盖的方法(安装/提交)中抛出异常,这然后在回滚发生之前给我几个错误对话框,然后回滚并不总是卸载服务。
在不使用 WiX 或类似选项的情况下,最干净的方法是什么?
Dozens of Q&A entries (all but one in stackoverflow!) that I found got close to this question, but didn't teach me what I needed. I have what should be a nearly simple installation: a Windows service and an associated tray icon application. They install fine with the standard VS Setup project. After the files are installed, I need to present a dialog to the user to set some parameters in the service's exe.config file. In that dialog, the user should be able to abort the installation. I've tried two approaches to the Custom Action process and ran into a wall with each when it comes to making the installation roll back.
Approach 1: An exe for the Custom Action, run at Commit time.
This sort-of works. The application returns a non-zero exit code and the installation rollback occurs. What I don't like is that:
- When the app exits (after the user selects to Cancel), the installation displays an error message saying that there was a problem with the installation and the user should contact the vendor. Since that's not the case, I'd prefer a more correct message ("Installation canceled by user") or no message at all.
- Both of the project outputs (the service and the tray app) have to be listed under all four Custom Action sections or my dialog won't appear. Instead, an error appears about a missing InstallState file and the installation always fails. Intuitively, this seems wrong.
Approach 2: An Installer as the Custom Action, run at Install or Commit time.
This is cleaner to me (only the one item listed in the Custom Actions), but getting the process to roll back is worse than Approach 1. It seems that I have to throw an exception in the overridden method (Install/Commit), which then gives me several error dialogs before the rollback occurs, and then the rollback doesn't always uninstall the service.
What is the cleanest way to make this work without going to WiX or similar options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简单的答案是不要使用 VS 安装程序类。它们存在许多基本的设计缺陷。我建议您改为查看 Windows Installer XML (WiX) 部署工具基础 (DTF)。 DTF 是一个非常优越的托管模型/互操作库,用于托管代码和输出与 C/C++ 自定义操作兼容(从 MSI 角度来看)的 DLL。它们可以作为自定义操作被任何 MSI 创作工具使用,而不仅仅是 WiX 安装程序。
部署工具基金会加入 WiX 工具集.
部署工具基础 (DTF) 托管自定义行动
The simple answer is don't use VS Installer Classes. They have a number of fundamental design flaws. I suggest you look at Windows Installer XML's ( WiX ) Deployment Tools Foundation ( DTF ) instead. DTF is a far superior hosting model / interop library for your managed code and outputs DLL's that are compatible ( from an MSI perspective ) with C/C++ custom actions. They can be consumed as Custom Actions by any MSI authoring tool, not just WiX installers.
Deployment Tools Foundation joins the WiX toolset.
Deployment Tools Foundation (DTF) Managed Custom Actions
我推荐这种方法:
这样在安装之前收集信息,用户也可以毫无问题地中止安装。
Visual Studio 不支持此方法,但可以使用免费或商业设置创作工具来完成。
如果您想坚持使用自定义操作,您可以尝试以下操作:
I recommend this approach:
This way the information is gathered before the install and the user can also abort the install without problems.
This approach is not supported by Visual Studio, but it can be done with free or commercial setup authoring tools.
If you want to stick with a custom action, you can try this: