Saturday 27 March 2010

Ektron and Web Application Projects (Part 3)

In this series of posts I’ve described a method of keeping your code and the required Ektron workarea separated.  This method essentially turns the ‘drop-in compiled workarea’ feature request on it’s head, by dropping your compiled code into the work area.  It’s the same result, just a slightly difference process (that you can do right now!):

  • In Part 1, I discussed why you might want to develop your website outside of the default Ektron workarea and gave a brief overview of your options.
  • In Part 2, I described how to organise the VS solution and configure IIS for use with Ektron workarea.

In this final part, I’ll describe how to combine your code with the Ektron workarea for final deployment.

Leveraging the Post-Build Event

The key to the whole process is the Post-Build Event in the clientproject.Website Web Application (see Part 2).  We can use this to copy your compiled code into the workarea website using a set of xcopy (or similar)commands.  To edit the Post-Build event right click on the clientproject.Website project and click ‘View Properties’ it will be on the ‘Build Events’ tab.  There’s a handy editor that let’s you know the values of various ‘macros’ for your project.  These macros are resolved automatically before the commands are executed and mean you don’t have to hard code absolute locations into your project.

Post-Build Event Editor in VS2008

These should include any css or js that your templates need, an example entry into the Post-Build Event could be:

   1: "$(SolutionDir)3rd Party\Tools\CodebehindRemover\CodebehindRemover" /i="$(ProjectDir)." /o="$(SolutionDir)web\." /e="ascx,aspx,master,asmx,ascx,svc,htm,html" 
   2: xcopy "$(ProjectDir)js" "$(SolutionDir)Web\js" /E /I /R /D /C /Y
   3: xcopy "$(ProjectDir)ui" "$(SolutionDir)Web\ui" /E /I /R /D /C /Y
   4: xcopy "$(ProjectDir)video" "$(SolutionDir)Web\video" /E /I /R /D /C /Y
   5: xcopy "$(ProjectDir)Xml" "$(SolutionDir)Web\Xml" /E /I /R /D /C /Y
   6: xcopy "$(ProjectDir)Xslt" "$(SolutionDir)Web\Xslt" /E /I /R /D /C /Y 
   7:  
   8: xcopy "$(ProjectDir)App_Browsers\*.*" "$(SolutionDir)Web\App_Browsers" /I /R /D /Y
   9: xcopy "$(ProjectDir)Configs\*.config" "$(SolutionDir)Web\Configs" /I /R /D /Y
  10: xcopy "$(ProjectDir)Configs\*.config.*" "$(SolutionDir)Web\Configs" /I /R /D /Y
  11: xcopy "$(ProjectDir)bin\*.dll" "$(SolutionDir)Web\bin" /E /I /R /D /C /Y
  12: xcopy "$(ProjectDir)bin\*.pdb" "$(SolutionDir)Web\bin" /E /I /R /D /C /Y
  13: xcopy "$(ProjectDir)bin\*.xml" "$(SolutionDir)Web\bin" /E /I /R /D /C /Y
  14: xcopy "$(ProjectDir)App_GlobalResources\*.resx" "$(SolutionDir)Web\App_GlobalResources" /I /R /D /Y 

You’ll notice that I’ve not included any of the .Net UI files (aspx, ascx, asmx, ashx, etc)  within the xcopy statements.  That’s because one of the implementation differences between Web Applications and Web Sites is that WAPS refer to their codebehind file using the codebehind page directive attribute, and websites use codefile.  Usually, when you compile (or precompile) a WS or WAP project those references get ignored as there’s no code file necessary.  However, when you’re trying to get ASP.Net to use a WAP aspx in a website you’ll get a compilation error. 

Fortunately, you don’t need a code file for the site to work – only for the ‘inherits’ attribute to be point towards your WAP page class.  So you can use a simple script/command line utility to remove any codebehind or codefile attributes as part of the Post-Build processing.  I’ve attached the source code for a basic command line application that I wrote to do this (imaginatively named CodeBehindRemover!) , the usage for the app is on line 1 of the code sample above.

With the post-build event in place, when you build your Web Application Project it will automatically be deployed into the vanilla workarea website.

Tip: If your IIS is locking your website files and preventing deployment you can add ‘iisreset /stop’ into the Pre-Build event and ‘iisreset /restart’ at the end of the Post-Build event

Attachment: Code Behind Remover

9 comments:

  1. hi.., myself is azad singh, i have just started to learn .net few times, so i am have no idea about this, but after read your post, i feel, it is really informative information. thanks
    Legit Online Jobs

    ReplyDelete
  2. Martin,

    Hey good article. I have done pretty much exactly option 2 before you wrote the article. If you were to go down the path of option 3, how would that impact esync. Is there a way to get esync to work on a folder outside of the workarea site?

    ReplyDelete
  3. Hi Blackdynamo,

    Sorry about the confusion with the comment - I've got moderation switched on as I've had a few spam messages.

    You can request a minimum eSync workarea from Ektron (for your specific version) which will just contain the bare minimum required to support eSync. You can then just create a virtual application called 'workarea' under your WAP and point at the minimal workarea website.

    ReplyDelete
  4. Alright..I'll see if we can't try that. The other thing that I find might struggle is the "load balancing" which I truly think they should call "asset balancing". I will try this out and see what happens.

    ReplyDelete
  5. It should work fine with load balancing. I've got a couple of installations working with load balanced frontend servers eSynced from an authoring server that I've used this style of solution on.

    Works well (and is considerably faster than the full workarea deployment)

    ReplyDelete
  6. "Ektron supports both Web Site and Web Application projects in 8.5 (released 2011)"
    So, does it mean, we don't have to use postbuild event as part of compiling the website?
    Where can we get Ektron8.5 minsite as webapplication?

    ReplyDelete
  7. @Vijay, I've had a look at Ektron 8.5 and it appears I was misinformed about the seperate authoring area. I guess it just wasn't worth the dev time (and support issues) for Ektron. :(

    ReplyDelete
  8. Martin,
    I am attempting to make this separation as I'm growing tired of the errors I receive from the Ektron code everytime I make a change to my code and compile. Can you supply screen shots of the IIS set up and what your project looks like from VS?

    ReplyDelete
  9. I'd like to drop Code Behind Remover into a project for an internal company product. Not for resale, but the product will have commercial use. Would you license (or publicly release) the code for that? If so, could you attach a license to the project?

    Nice blog. I'm a longtime .NET guy just beginning to use Ektron.

    ReplyDelete

Got something to say? Let it out then!
Comments are moderated, so it may take a while to for them to be displayed here!