如何在自定义操作中使用 VS Installer 类

发布于 2024-10-23 16:47:08 字数 682 浏览 5 评论 0原文

我发现了数十个问答条目(除了 stackoverflow 中的一个之外)都接近这个问题,但没有告诉我我需要什么。我的安装几乎是简单的:一个 Windows 服务和一个关联的托盘图标应用程序。它们可以与标准 VS 安装项目很好地安装。安装文件后,我需要向用户显示一个对话框,以在服务的 exe.config 文件中设置一些参数。在该对话框中,用户应该能够中止安装。我尝试了两种自定义操作过程的方法,但在回滚安装时都遇到了困难。

方法 1:自定义操作的 exe,在提交时运行。 这种工作。应用程序返回非零退出代码并发生安装回滚。我不喜欢的是:

  1. 当应用程序退出时(用户选择取消后),安装会显示一条错误消息,指出安装出现问题,用户应联系供应商。由于情况并非如此,我希望有更正确的消息(“用户取消安装”)或根本没有消息。
  2. 两个项目输出(服务和托盘应用程序)都必须列在所有四个自定义操作部分下,否则我的对话框将不会出现。相反,会出现有关缺少 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:

  1. 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.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与酒说心事 2024-10-30 16:47:08

简单的答案是不要使用 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

红玫瑰 2024-10-30 16:47:08

我推荐这种方法:

  • 创建一个自定义安装对话框,询问用户您的选项
  • 使用此对话框设置的安装程序属性来修改您的服务配置文件(您可以使用自定义操作或其他安装创作工具的 XML 支持)

这样在安装之前收集信息,用户也可以毫无问题地中止安装。

Visual Studio 不支持此方法,但可以使用免费或商业设置创作工具来完成。

如果您想坚持使用自定义操作,您可以尝试以下操作:

  • 确保您的自定义操作被推迟并且在提交期间不会运行(提交意味着安装已执行并且没有回滚)
  • 使用 Win32 DLL 来显示您的自定义操作对话;这样您就可以返回 ERROR_INSTALL_USEREXIT (1602)因此会显示更友好的用户退出对话框,而不是致命错误对话框

I recommend this approach:

  • create a custom installation dialog which asks the user about your options
  • use the installer properties set by this dialog to modify your service configuration file (you can use a custom action or the XML support of another setup authoring tool)

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:

  • make sure your custom action is deferred and doesn't run during commit (commit means that the installation was performed and there's no rollback)
  • use a Win32 DLL to show your custom dialog; this way you can return ERROR_INSTALL_USEREXIT (1602) so a friendlier user exit dialog is shown instead of the fatal error dialog
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文