Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nant vs. msbuild: stopping a service

I'm trying to decide which side I'm on in the MsBuild vs. Nant war. I'm starting with: stop a service, deploy some files, restart the service. Just from looking at these two links, that is much easier to do in Nant.

MSBuild: Example of using Service Exists MSBuild task in Microsoft.Sdc.Tasks?

<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) 
                                { 
         etc... 

Nant: http://ryepup.unwashedmeme.com/blog/2007/01/04/restart-a-windows-service-remotely/

<!-- Send the stop request -->
<exec program="sc.exe">
  <arg line="\\server stop shibd_Default"/>
</exec>
<!-- Sleep a little bit, to give the service a chance to stop -->
<sleep seconds="5"/>
<!-- Send the start request -->
<exec program="sc.exe">
  <arg line="\\server start shibd_Default"/>
</exec>

I wonder if the SO community agrees with me. Is it much easier to get basic things like this done in Nant? Sure looks that way. C# code in a CDATA block? WTF?

Our current build process is a) lots of bat files b) lots of cursing. I'd really like to find a good replacement, but that MsBuild stuff looks like a world of pain to my eyes. I'm thinking the way to go is to build scripts in Nant, then use MsBuild to do any .NET builds that need to be done.

One important question: which one is better at catching errors in the script before the script is run? I was thinking of rolling my own here and that was very important part of it: line up all your data and make sure that it makes sense before attempting to run.

like image 810
jcollum Avatar asked Nov 30 '22 11:11

jcollum


1 Answers

In msbuild you could also use the ServiceController task that is packaged in the msbuild community tasks.

like image 60
mockobject Avatar answered Dec 06 '22 14:12

mockobject