Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Continuous Integration Tip #2 – Using App_offline.htm in Your Build

DZone's Guide to

Continuous Integration Tip #2 – Using App_offline.htm in Your Build

· DevOps Zone
Free Resource

The Nexus Suite is uniquely architected for a DevOps native world and creates value early in the development pipeline, provides precise contextual controls at every phase, and accelerates DevOps innovation with automation you can trust. Read how in this ebook.

Deploying in an automated fashion using Continuous Integration doesn’t happen instantly, and depending on the size of your application, your continuous integration deployment can get caught in a state of unknown/in-between if a user visits your application half way through deployment. This can be far from optimal, but ASP.Net has a trick up it’s sleave in the form of the App_offline.htm file.

image This is the second post in a series on Continuous Integration Tips & Tricks in follow up to a post i made about setting up Continuous Integration Automated Deployment with Web Deployment Projects & Team City.

While there has been quite a bit of broadcast advertisement of the App_offline file over the years, whenever i bring it up with developers i usually get a blank stare in reply.

Basically the gist of this is simple: if you place a file named app_offline.htm in the root of your application, all requests to asp.net pages or web services, is met by the contents of this file.

Because of this really cool feature that ASP.Net has on offer, we can use it to our advantage in our automated build. What we need to do is copy a file into the root of our application before we copy the site.

The example build file

In all my examples, I've been using Microsoft Web Deployment Projects and TeamCity. This solution uses MSBUILD for it’s automation, therefore I’m going to show you an example MSBUILD script that you can add to your web deployment project. You'll have to alter these for your build provider of choice if you use a different one (Nant etc).

Create an HTML file called DeploymentInProgress.htm in the root of your application (it can be anywhere, as long as you update your build script to reflect the new path) and in it put some HTML that mentions that the app is being deployed. I suggest that if you use CSS include all the styles in the header instead of linking to it, and if you use any images in the page they are hosted on another domain/location (because you’ll be deploying your site and want to make sure the image file you calls exists and hasn’t been deleted by your deployment process).

Add the following to bottom of your Web Deployment project file.

<Target Name="AfterBuild">
    <PropertyGroup>
    <!-- This is where i want to copy my deployment to-->
        <DeploymentDestination>C:\MyIISRoot\</DeploymentDestination>
    </PropertyGroup>
    <ItemGroup>
        <FilesToCopy Include="$(OutputPath)\**\*.*" />
    </ItemGroup>

    <!-- Copy the App Offline file-->
    <Copy SourceFiles="$(OutputPath)DeploymentInProgress.htm" 
                DestinationFiles="$(DeploymentDestination)app_offline.htm" />
    
    <!-- Copy the deployment files-->
    <Copy SourceFiles="@(FilesToCopy)" 
                DestinationFiles="@(FilesToCopy->'$(DeploymentDestination)%(RecursiveDir)%(Filename)%(Extension)')" />
    <!-- Delete the app offline file-->
    <Delete Files="$(DeploymentDestination)app_offline.htm" />
</Target>

This will copy your file (in the process renaming it to app_offline.htm), copy your project files, and then delete the app_offline.htm file so that your application can start.

This can  be further integrated with the ftp upload i mentioned in the previous post to give a remote deployment option.

The DevOps Zone is brought to you in partnership with Sonatype Nexus.  See how the Nexus platform infuses precise open source component intelligence into the DevOps pipeline early, everywhere, and at scale. Read how in this ebook

Topics:

Published at DZone with permission of Douglas Rathbone, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}