Dentaku

Per Zimmerman's personal blog

« Back

Problem with themes in a precompiled "updateable" ASP.NET web

If you precompile a web site with a theme set, the compiler adds the theme setting into the @Page directive on every ASPX page in the site. Probably not what you'd expect. On my last day at work before my vacation I stumbled upon this unexpected problem. The only thing I needed to do before leaving work was to my compile web site and deploy it. The web site was to be deployed in three versions with different themes. I spent the last frustrating hour trying to find out why all three web looked same theme after I had deployed them. I had changed the <pages theme="theme1" />, and all three sites had different themes set. Everything looked right, but still it didn't work. I had compiled the site as an updateble web site. At last I found out that if I didn't set a theme in web.config before I compiled the web. I could change it afterwards. I didn't have the time to check what the real problem was. During my vacation, my co worker Johan Dewe was handling the project. So he had to deal with the problem when I was away. He wrote a post about this on his blog (in Swedish): Theme settings i web.config i kombination med förkompilerad ASP.Net. He also found that K. Scott Allen wrote Caveat With ASP.NET Precompilation and web.config Settings.

Johan also has a solution how to make deployment projects which fix the theme problem: Search and replace med MSBuild och Web Deployment Project. Because it's in Swedish I'll give you a rough translation. You have to use Web Deployment Project (WDP) och MSBuild Community Tasks. Download and install the MSBuild Community Tasks, update your WDP file and add this reference to the target file <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

Remove theme before compile

  1. Create a new WDP and open the project file.
  2. Make sure that a temporary folder is created for the source files by extend the elementet PropertyGroup:
    <EnableCopyBeforeBuild>true</EnableCopyBeforeBuild>
  3. Update BeforeBuild target by adding a task that removes the theme setting from the <pages>-element:
        <Target Name="BeforeBuild">
            <FileUpdate
                Files="$(CopyBeforeBuildTargetPath)\web.config"
                Regex="(\u003Cpages.*)(theme=\u0022.*?\u0022)"
                ReplacementText="$1" />
            </Target>

So before the site is compiled the theme-setting will be removed and not added to every page.

2006-08-23 23:22:00 | Posted in ASP.NET | Link | digg this

3 Comments

2006-09-05 07:48:00 From: Brock

Thanks for posting this. What an annoying problem. I hope that they treat this as a bug because this is in no way desired behaviour.

2006-09-26 13:50:00 From: Bass

Thanks for the post. Been looking after this problem all day now. Never had thought it would be something like this.

2008-01-14 12:30:00 From: hudkjcyu

vmkftplf http://xxehypeh.com hembmwmy hipjajcc wqwcsiyr [URL=http://adiijshw.com]gkootujq[/URL]