c# - 什么启动 Windows 服务安装程序的安装?

标签 c# .net windows-services

我使用 Microsoft's walkthrough 创建了一个服务.

它有效。但我不明白怎么办。 Main() 方法似乎没有调用 ProjectInstaller 构造函数(它看起来像是安装服务的函数)。事实上,解决方案中的任何地方都没有引用 ProjectInstaller(我使用 Shift+F12 检查)。

那么它是如何执行的呢?

编辑

我没有使用installutilProgramMain() 调用 ManagedInstallerClass.InstallHelper(args);

最佳答案

用于安装该服务的程序 (installutil.exe) 会检查您的程序集并运行安装程序。如其 documentation 中所述:

Installutil.exe uses reflection to inspect the specified assemblies and to find all Installer types that have the System.ComponentModel.RunInstallerAttribute attribute set to true.

The tool then executes either the Installer.Install or the Installer.Uninstall method on each instance of the Installer type. Installutil.exe performs installation in a transactional manner; that is, if one of the assemblies fails to install, it rolls back the installations of all other assemblies. Uninstall is not transactional.

更新:您说您不使用installutil,而是使用ManagedInstallerClass.InstallHelper。阅读该类的文档:

This API supports the product infrastructure and is not intended to be used directly from your code.

Handles the functionality of the Installutil.exe (Installer Tool).

所以首先你不应该使用它,其次 - 它与 installutil 的作用相同(因此与这个问题相关 - 使用反射来检查你的程序集并运行安装程序)。我认为 installutil 工具实际上只是调用此方法。请注意,您必须在 ManagedInstallerClass.InstallHelperargs 中传递程序集的路径,这样它就知道要通过反射检查哪个程序集并运行安装程序。

关于c# - 什么启动 Windows 服务安装程序的安装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49777868/

相关文章:

c# - 如何找到windows服务exe路径

c# - System.Type.FullName 的意外值

c# - 发送带有送达信息的短信

c# - 如何递归获取命名空间内的所有命名空间

c# - 将 BMP 转换为 PCX C# Compact Framework

.net - 使用 .NET 修改 Excel 电子表格

c# - 您能否以编程方式更改现有 Windows 服务的显示名称(和其他属性)?

c# - 如何使用户控件像窗口一样在屏幕上可拖动

c# - IS vs. AS vs. IsAssignableFrom - 检查对象类型和接口(interface)时有什么区别?

proxy - cntlm 服务未运行