简体   繁体   English

是什么启动Windows Service Installer的安装?

[英]What launches the installation of a Windows Service Installer?

I have created a Service using Microsoft's walkthrough . 我已经使用Microsoft的演练创建了服务。

It works. 有用。 But I don't understand how. 但是我不知道如何。 The Main() method doesn't seem to call the ProjectInstaller constructor (which looks like what installs the service). Main()方法似乎没有调用ProjectInstaller构造函数(看起来像安装服务的样子)。 In fact, ProjectInstaller isn't referenced anywhere in the solution (I checked using Shift + F12 ). 实际上,解决方案中的任何地方都没有引用ProjectInstaller (我使用Shift + F12进行了检查)。

So how is it executed? 那么如何执行呢?

EDIT 编辑

I'm not using installutil . 我没有使用installutil Program 's Main() calls ManagedInstallerClass.InstallHelper(args); ProgramMain()调用ManagedInstallerClass.InstallHelper(args); .

Program which you use to install that service ( installutil.exe ) inspects your assembly and runs installers. 用于安装该服务的程序( installutil.exe )将检查您的程序集并运行安装程序。 As stated in its 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. Installutil.exe使用反射检查指定的程序集并查找将System.ComponentModel.RunInstallerAttribute属性设置为true的所有Installer类型。

The tool then executes either the Installer.Install or the Installer.Uninstall method on each instance of the Installer type. 然后,该工具在Installer类型的每个实例上执行Installer.Install或Installer.Uninstall方法。 Installutil.exe performs installation in a transactional manner; Installutil.exe以事务方式执行安装; that is, if one of the assemblies fails to install, it rolls back the installations of all other assemblies. 也就是说,如果其中一个程序集安装失败,则会回滚所有其他程序集的安装。 Uninstall is not transactional. 卸载不是事务性的。

Update: You said you do not use installutil and instead using ManagedInstallerClass.InstallHelper . 更新:您说您不使用installutil而是使用ManagedInstallerClass.InstallHelper Reading documentation of this class: 阅读此类的文档:

This API supports the product infrastructure and is not intended to be used directly from your code. 此API支持产品基础结构,不能直接在您的代码中使用。

Handles the functionality of the Installutil.exe (Installer Tool). 处理Installutil.exe(安装程序工具)的功能。

So first you should not be using it, and second - it does the same as installutil (so related to this question - uses reflection to inspect your assembly and run installers). 因此,首先您不应该使用它,其次-它与installutil相同(因此与此问题相关-使用反射检查您的程序集并运行安装程序)。 I suppose that installutil tool actually just calls this method. 我想installutil工具实际上只是调用此方法。 Note that you have to pass path to your assembly in args of ManagedInstallerClass.InstallHelper , that's how it knows which assembly to inspect with reflection and run installer for. 请注意,您必须在ManagedInstallerClass.InstallHelper args中传递程序集的路径,这就是它知道如何使用反射检查哪个程序集并运行安装程序的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM