So you have your Umbraco project nicely hooked up to a continuous integration or build server such as TeamCity. So how do you automate the content publishing so your users see the latest version everytime?

At Tekcent we develop Umbraco projects using a shared database as this makes collaboration and working in teams easier. So the following steps is intended for this setup.  I will cover the different collaboration options for teams in another blog post.

CI setups are a joy since they can automate the build and deployment process for you.  As often during with the development process you will make a bunch of changes to the content database...With a few lines of code you can easily automated publishing from your CI server so you don't have to login to click the "Republish entire website"

  1. Using Visual Studio add a Generic Handler to your Umbraco project 2013 06 15 01 04 12
  2. The generic handler and corresponding code files will be added to your Visual Studio project
    2013 06 15 01 12 41
  3. Edit the codefile and add some code to call into Umbraco's RefreshContent() method.  This will trigger the republishing routine on the server

    using System.Web;
    namespace UmbracoRepublish
        /// Summary description for RefreshContent
        public class RefreshContent : IHttpHandler
            public void ProcessRequest(HttpContext context)
                context.Response.ContentType = "text/plain";
                context.Response.Write("Content Refreshed");
            public bool IsReusable
                    return false;
  4. Compile and run your project. Open the link to your newly created handler in the web browser. You should see "Content Refreshed" displayed on the web browser. It's worth noting that you can redirect back to the homepage at this point - I've chosen to display a message. What's important is that the RefreshContent() method is being called, this is where the "magic" happens
    2013 06 15 17 25 43
  5. Add a post build step to call your handler. We'll use a Powershelll script to do this

    (new-object net.webclient).DownloadString("http://localhost:56713/refreshcontent.ashx")
    2013 06 15 17 43 24
  6. Make sure your handler is the last step in the build process 2013 06 15 18 19 46
  7. Run the build...Remember the message that we send in the response?2013 06 15 18 26 44
  8. Finally, the all important green light
    2013 06 15 18 29 51

Saturday June 1, 2013, By Anton Pham

comments powered by Disqus

Share this page