如何在自定义操作中使用VS Installer类 [英] How to use VS Installer class in a Custom Action

查看:281
本文介绍了如何在自定义操作中使用VS Installer类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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. 当应用程序退出时(在用户选择取消后),安装程序显示错误消息表示安装存在问题,用户应与供应商联系。既然不是这种情况,我希望有一条更正确的消息(用户取消安装)或根本没有消息。

  2. 项目的两个输出(服务和任务栏)应用程序)必须列在所有四个自定义操作部分下,否则我的对话框将不会出现。而是,出现有关缺少InstallState文件的错误,并且安装始终失败。直观上看,这似乎是错误的。

  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.

方法2:安装程序作为自定义操作,在安装或提交时运行。
这对我来说比较干净(仅自定义操作中列出的一项),但是使过程回滚的方法比方法1差。似乎我必须在重写的方法中抛出异常(安装/提交),然后在回滚发生之前会给我几个错误对话框,然后回滚并不总是卸载该服务。

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.

在不使用WiX或类似选项的情况下,最干净的方法是什么?

What is the cleanest way to make this work without going to WiX or similar options?

推荐答案

简单的答案是不要使用VS Installer类。它们具有许多基本的设计缺陷。建议您改用Windows Installer XML(WiX)部署工具基金会(DTF)。 DTF是托管代码的高级托管模型/互操作库,并输出与C / C ++自定义操作兼容的DLL(从MSI角度来看)。任何MSI创作工具都可以将它们作为定制操作使用,而不仅仅是WiX安装程序。

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.

部署工具基金会加入了WiX工具集。

部署工具基金会(DTF)托管自定义操作

这篇关于如何在自定义操作中使用VS Installer类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆