Service Usage Example Is there an MSBuild task in Microsoft.Sdc.Tasks?

I am trying to use Microsoft.Sdc.Tasks.ServiceProcess.Exists to check for the presence or absence of a service. However, there is no example using this document. Anybody have?

+1
source share
2 answers

I have not used this in production at all, and I'm not sure which version you have (I have Release 2.1.3155.0 version), and according to the accompanying .chm help file, the Task has the following properties:

  • DoesExist Returns TRUE if the specified service.
  • IsDisabled Returns TRUE if the service is disabled.
  • ServiceName An abbreviated name that identifies a service on the system.

ServiceName must be set to "Short name that identifies the service for the system, such as" W3SVC ".

You can try to try a well-known service (for example, mssqlserver) and check the result of two other properties (DoExist / IsDisabled).

Update: here's the sample (works):

Import tasks, then call (for example)

<Microsoft.Sdc.Tasks.ServiceProcess.Exists ServiceName = "Server"> <Output TaskParameter = "IsExist" PropertyName = "Exists" / "> </Microsoft.Sdc.Tasks.ServiceProcess.Exists>

<Message text = "Does the service exist? $ (Exists)" / ">

+1
source

Here's how we check if a service exists, stop it, if so, do something and start the service again (if it was and it was running).

Assistant Objective:

 <target name="service_exists"> <script language="C#"> <references> <include name="System.ServiceProcess.dll" /> </references> <code><![CDATA[ public static void ScriptMain(Project project) { String serviceName = project.Properties["service.name"]; project.Properties["service.exists"] = "false"; project.Properties["service.running"] = "false"; System.ServiceProcess.ServiceController[] scServices; scServices = System.ServiceProcess.ServiceController.GetServices(); foreach (System.ServiceProcess.ServiceController scTemp in scServices) { if (String.Compare(scTemp.ServiceName.ToUpper(), serviceName.ToUpper()) == 0) { project.Properties["service.exists"] = "true"; project.Log(Level.Info, "Service " + serviceName + " exists"); if (scTemp.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Running)) project.Properties["service.running"] = "true"; project.Log(Level.Info, "Service " + serviceName + " is running: " + project.Properties["service.running"]); return; } } project.Log(Level.Info, "Service " + serviceName + " doesn't exist"); } ]]></code> </script> </target> 

Using:

 <property name="service.name" value="Selection.Service" /> <call target="service_exists" /> <servicecontroller action="Stop" service="${service.name}" machine="${host}" timeout="60000" if="${service.exists}"/> <!-- Do something --> <servicecontroller action="Start" service="${service.name}" machine="${host}" timeout="60000" if="${bool::parse(service.exists) and bool::parse(service.running) == true}"/> 

I hope I havenโ€™t missed anything - our build manager stores everything in one msbuild file, which now contains more than 3600 lines: |

+2
source

Source: https://habr.com/ru/post/1300259/


All Articles