views:

568

answers:

5

Is it possible to instruct the aspnet_compiler to set debug=false in the web.config?

My intention is to automate this as part of the nant build process. I am open to suggestions other than xml parsing

+1  A: 

The way I tackle this is I have seperate configuration files for each deployment environment:

  • Production
  • Staging
  • Development

Upon the "build script", I copy the config files for the type I am building. For example, on Staging I would copy the /configs/staging/*.config into the root of the website. Then, my script would call aspnet_compiler to compile the application.

eduncan911
+1. I actually take this a step further and deploy multiple web.config files, named web.config.empty, web.config.default, etc... that way 1) I never overwrite an existing web.config file, and 2) users can review the settings used in different ways.
overslacked
It also helps when you have a 10+ person team of developers, all with SQL installed locally, Vista IIS7 vs XP's IIS6 configs, etc. The team just has to be trained that "when a config is changed, make sure is propogated throughout all other config files"
eduncan911
+8  A: 

Have you thought about using <xmlpoke>?

<xmlpoke file="${Build.WebConfig}" 
    xpath="/configuration/system.web/compilation/@debug" 
    value="false">
</xmlpoke>

NAnt Home Page

XML Poke Documentation

Michael La Voie
I recommend adding links to the NAnt home page and the xmlpoke documentation.
Keith Walton
xml parsing it is :-)
Cherian
+2  A: 

I would suggest using entirely different config files for each environment(prod, test, staging in our case). Depending on the build you would just use the required config, no mess, less fuss. Hanselmen has example on how to do this in Visual Studio and if you read the first comment Phil Hack has got it working with NAnt.

 <target name="configMerge">  
     <copy file="${sourcefile}"  
         tofile="${destinationfile}" overwrite="true">  
       <filterchain>  
         <expandproperties />  
       </filterchain>  
     </copy>  
   </target>  

In Addition, if you are using VS 2010 you can now use web.config transforms

cgreeno
A: 

I've been using this tool as part of my build chain. It allows conditional configuration settings within a single xml file based on build settings.

http://xmlpreprocess.sourceforge.net/

Andrew Rollings
A: 

Using web deployment projects you can swap out different sections of your web.config after your build.

pattersonc