title: nant vs. msbuild: stopping a service
body: <p>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. </p>
  
  <p>MSBuild: <a href="https://stackoverflow.com/questions/173393/example-of-using-service-exists-msbuild-task-in-microsoft-sdc-tasks/173440#173440">Example of using Service Exists MSBuild task in Microsoft.Sdc.Tasks?</a></p>
  
  <pre><code>&lt;target name="service_exists"&gt; 
          &lt;script language="C#"&gt; 
                  &lt;references&gt; 
                          &lt;include name="System.ServiceProcess.dll" /&gt; 
                  &lt;/references&gt; 
                  &lt;code&gt;&lt;![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... 
  </code></pre>
  
  <p>Nant: <a href="http://ryepup.unwashedmeme.com/blog/2007/01/04/restart-a-windows-service-remotely/" rel="nofollow noreferrer">http://ryepup.unwashedmeme.com/blog/2007/01/04/restart-a-windows-service-remotely/</a></p>
  
  <pre><code>&lt;!-- Send the stop request --&gt;
  &lt;exec program="sc.exe"&gt;
    &lt;arg line="\\server stop shibd_Default"/&gt;
  &lt;/exec&gt;
  &lt;!-- Sleep a little bit, to give the service a chance to stop --&gt;
  &lt;sleep seconds="5"/&gt;
  &lt;!-- Send the start request --&gt;
  &lt;exec program="sc.exe"&gt;
    &lt;arg line="\\server start shibd_Default"/&gt;
  &lt;/exec&gt;
  </code></pre>
  
  <p>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? </p>
  
  <p>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. </p>
  
  <p><strong>One important question</strong>: 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. </p>