title: Event Build pre & post to stop and restart Windows service
body: <p>I've been experimenting with using build events to start and stop Windows service that are being built in my project.  However for the pre &amp; post builds fail with an error level 255.  I've tried catching this with the pre-build with no luck.</p>
  
  <p>Pre-build</p>
  
  <pre><code>if "$(ConfigurationName)" == "Debug"
  (
   net stop myService
   if errorlevel 2 
      if errorlevel 255 
          :exit
  
     :exit
  )
  </code></pre>
  
  <p>Post-build</p>
  
  <pre><code>if "$(ConfigurationName)" == "Release"
  (
     copy $(TargetDir) C:\Media\Bin\$(ProjectName)
     if errorlevel 1 BuildEventFailed
  
     :BuildEventFailed
     mkdir C:\Media\Bin\$(ProjectName)
  
     copy $(TargetDir) C:\Media\Bin\$(ProjectName)
  )
  else if "$(ConfigurationName)" == "Debug"
  (
     net start myService
  )
  </code></pre>