How to use VS Installer class in a Custom Action

我们两清 提交于 2020-01-06 04:57:09

问题


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?


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/5342679/how-to-use-vs-installer-class-in-a-custom-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!