Tuesday, October 17, 2006

Replacing nested web.config sections using Web Deployment Projects

It's relatively straightforward to replace specific sections of a Visual Studio 2005 Web Site web.config using a Web Deployment Project. Scott Guthrie has a great blog post on the Web Deployment Project feature set, but I stumbled across a minor issue today when I tried to replace the compilation section.

To replace web.config sections, open the Web Deployment Property Pages and select Deployment in the left hand menu. Click the checkbox to Enable Web.config file section replacement. Whilst the examples hyperlink shows a tooltip on how to replace the appSettings and connectionStrings sections using sectionName=filename, when I attempted to replace the compilation element in the web.config, I received the following build error.

Error 2 web.config(1): error WDP00002: missing section compilation.

To successfully replace the compilation element or other nested elements, it's necessary to use an XPath expression. For example, system.web/compilation as below.


Web Deployment Project Property Pages

3 comments:

Anonymous said...

I couldn't get it to work when trying to replace the customErrors section.

I have:

system.web/customErrors=customErrors.config

and in that config, my custom errors section (which I can't post to this blog because it disallows scripting!)

but it still says:

the 'customErrors' element is not declared.

any suggestions?

cheers,
rich

Anonymous said...

I think that replacement syntax is case sensitive. But that looks good in your sample.
And in the customErrors.config file, start on the customErrors level (do not include system.web). Note that the visual studio designer complains here..
Regards, Jaap.

Anonymous said...

Thanks for sharing this. Helped me solve my problem by using the Xpath. Cheers.