What's the strange question about Windows ServicesDependedOn ???
The Code is as follows:
Public partial class WinServicePWServiceInstaller: Installer
{
Private ServiceProcessInstaller process;
Private ServiceInstaller service;
Private const string m_SERVICENAME = "myService ";
Public WinServicePWServiceInstaller ()
{
InitializeComponent ();
Process = new ServiceProcessInstaller ();
Process. Account = ServiceAccount. LocalSystem;
Service = new ServiceInstaller ();
Service. ServiceName = m_SERVICENAME;
Service. StartType = ServiceStartMode. Automatic;
Service. ServicesDependedOn = GetDepengOnServices ();
Installers. Add (process );
Installers. Add (service );
}
/// <Summary>
/// Obtain the dependency service of the configuration file
/// </Summary>
/// <Returns> </returns>
Private string [] GetDepengOnServices ()
{
String [] services = null;
String allService = ConfigurationManager. deleettings ["DependOnService"];
Services = new string [] {allService };
// Return services;
If (allService. IndexOf (';')! =-1)
{
Services = allService. Split (';');
}
Else
{
Services = new string [] {allService };
}
Return services;
}
}
GetDepengOnServices () written in the preceding method reports an error during installation.
No error will be reported if you change it to the following method:
/// <Summary>
/// Obtain the dependency service of the configuration file
/// </Summary>
/// <Returns> </returns>
Private string [] GetDepengOnServices ()
{
String [] services = null;
String allService = ConfigurationManager. deleettings ["DependOnService"];
Services = new string [] {allService };
Return services;
// If (allService. IndexOf (';')! =-1)
//{
// Services = allService. Split (';');
//}
// Else
//{
// Services = new string [] {allService };
//}
// Return services;
}
Read configuration section <! -- List of services the service depends on -->
<Add key = "DependOnService" value = "MSSQLSERVER"/>
After tracking, both methods can produce correct results. Why does the first method report an error during installation ????