Restarting the application pool using Nant

by Thomas 5. April 2008 13:45

I've had times where CruiseControl would not build because files were in use. This is despite the fact that I stop IIS prior to deploying files. So, I modified my deployment build script to also recycle the application pool. This solution builds on information from Artur Carvalho's blog.

 

<property name="appPoolName" value="DefaultAppPool" readonly="false" overwrite="true" />
<script language="C#">
    <references>
      <include name="System.DirectoryServices.dll" />
    </references>        
    <imports>
        <import namespace="System.DirectoryServices" />
    </imports>
    <code>
        <![CDATA[
        public static void ScriptMain( Project project )
        {
            string appPoolName = project.Properties["appPoolName"];
            DirectoryEntry apppools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
            DirectoryEntry newpool = apppools.Children.Find(appPoolName,"IIsApplicationPool");
            newpool.Invoke("stop",new object[]{});
            newpool.Invoke("start",new object[]{});
            newpool.CommitChanges();
        }
        ]]>
    </code>
</script>

 

Comments

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.0.7
Theme by Extensive SEO