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
- Create a new WDP and open the project file.
- Make sure that a temporary folder is created for the source files by extend the elementet PropertyGroup:
<EnableCopyBeforeBuild>true</EnableCopyBeforeBuild>
- 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