从安装程序类停止 Windows 服务时出现问题。事件发生得太晚了

发布于 2024-10-21 21:34:37 字数 715 浏览 1 评论 0原文

我正在使用 Visual Studio 2010 和 .NET 4.0。 我有一个从 Visual Studio 安装项目安装的 Windows 服务。在安装项目中,我将RemovePreviousVersion 属性设置为True。

在包含该服务的项目中,我有一个安装程序类,用于在从以前的版本升级时停止该服务。

因此,当升级软件时,服务已经存在并且可以运行。如果它正在运行,则在安装过程中安装程序会提示该文件已在使用中,并提供“重试”、“继续”或“退出安装”选项。在此阶段,我可以手动停止服务并单击重试,这将起作用。但我不希望最终用户必须这样做。

我已将消息框放在整个安装程序类 BeforeInstall、BeforeUninstall(安装程序事件)、Install、Uninstall、Commit、Rollback(覆盖方法)中,以便我可以看到在安装过程中何时调用这些内容。

运行安装时,在任何安装程序类代码之前都会显示文件正在使用的提示。一旦我停止服务并单击重试,就会继续,并且将显示安装类中的消息框。因此,肯定会调用安装程序类,但在实际执行任何操作的过程中为时已晚。

我不认为这是 .NET 早期版本中的行为?

有没有人遇到过这个问题或者有什么建议?

如果需要的话,我可以尝试 Visual Studio 2010 附带的 InstallShiled LE 项目(不确定这是否会产生相同的结果),但如果可能的话,我更愿意看看是否有人知道 Visual Studio 安装项目的解决方案。

I'm using Visual Studio 2010 with .NET 4.0.
I have a windows service that is installed from a Visual Studio Setup Project. In the setup project I have the RemovePreviousVersion property set to True.

In the project that contains the service I have an installer class that will be used to stop the service when upgrading from a previous version.

So when upgrading the software the service will already exist and could be running. If it is running then during the installation the installer prompts that the file is already in use and gives the option to Try Again, Continue or Exit Installation. At this stage I could stop the service manually and click Try Again and this will work. But I don't want the end user to have to do this.

I have put messagebox's throughout the installer class BeforeInstall, BeforeUninstall (installer events), Install, Uninstall, Commit, Rollback (overridden methods) so I can see when these are called during the installation.

When the install is run the prompt that the file is in use is displayed before any of the installer class code. Once I stop the service and click try again is will continue and the messagebox's in the install classes will be displayed. So the installer class is definately being called it's just too late in the process to actually do anything.

I don't think this was the behaviour in earlier versions of .NET?

Has anyone come across this problem or have any suggestions?

I could try the InstallShiled LE Project that comes with Visual Studio 2010 if I needed to (not sure if that would give the same result) but would prefer to see if anyone knows a solution with the Visual Studio Setup Project if possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

吻风 2024-10-28 21:34:37

FilesInUse 安装程序对话框会显示重试消息。在InstallValidate操作期间,Windows Installer 会自动检测正在使用的文件并提示用户有关这些文件的信息。

解决方案是在 InstallValidate 操作之前停止(不删除)服务。这可以通过自定义操作来完成。

请注意,您无法在使用 Visual Studio InstallValidate 之前设置自定义操作。但是,您可以在生成并更改 MSI 后使用 Orca 对其进行编辑InstallExecuteSequence 表中的操作序列。

大多数商业设置创作工具和 WiX 支持自定义操作序列。

The try again message is shown by FilesInUse installer dialog. During InstallValidate action Windows Installer automatically detects files in use and prompts the user about them.

A solution is to stop (without removing) the service before InstallValidate action. This can be done through a custom action.

Please note that you cannot set a custom action before InstallValidate with Visual Studio. However, you can edit the MSI with Orca after it's generated and change the action sequence in InstallExecuteSequence table.

Most commercial setup authoring tools and WiX support custom sequences for your actions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文