The solution to this case is very difficult to find, but I think I was able to find it here , I'll explain it to you.
1st - Create a class Installer
, it must be public, non-static, inherit from Installer
and be decorated with the RunInstaller
attribute with true
parameter. >
[RunInstaller(true)]
public class MeuServicoInstaller : Installer
{
public MeuServicoInstaller()
{
ServiceProcessInstaller processInstaller = new ServiceProcessInstaller();
processInstaller.Account = ServiceAccount.LocalSystem;
ServiceInstaller mainServiceInstaller = new ServiceInstaller();
mainServiceInstaller.ServiceName = "Service1";
mainServiceInstaller.Description = "Service One que faz tal coisa";
mainServiceInstaller.ServicesDependedOn = new string [] { "Service2" };
ServiceInstaller secondServiceInstaller = new ServiceInstaller();
secondServiceInstaller.ServiceName = "Service2";
secondServiceInstaller.Description = "Service Two que faz tal coisa";
Installers.Add(processInstaller);
Installers.Add(mainServiceInstaller);
Installers.Add(secondaryServiceInstaller);
}
}
In the constructor of this class you add your services in the way that the example shows, attention to the line containing ServicesDependedOn
, there it says that serviço 1
depends on serviço 2
, so when the first is called, the second it will also be because it is dependent.
2nd - This class you created will be invoked and instantiated when you run the InstallUtil.exe
process.
Note: Note the names of the services, they must be the same. I even advise using the keyword nameof
to maintain the consistency of names instead of strings
.
Examples:
mainServiceInstaller.ServiceName = nameof(Service1);
mainServiceInstaller.ServicesDependedOn = new string [] { nameof(Service2) };