Search code examples
asp.netvisual-studioconfigurationweb-configproduction

Switch web.config transformations in production?


I know this is a long shot.

What I'm hoping is that there is a way to deploy multiple copies of a Web.config file to the production environment as part of packaged code (let's call them Web.config.prod and Web.config.prodTest) so that regression testers can test on a disconnected production server (using prodTest) in a different namespace (e.g., prodtest.com) prior to making it go live (say, using prod on prod.com) without doing two separate deployments.

Short of making a PowerShell script to swap out the values, I can't think of a good way to do this. Every project I've seen so far has a single .config file made as part of the build.

Does anyone have any suggestions?

Thanks!


Solution

  • For some settings (the ones most likely to change) you can put both in the web.config and have the code select the appropriate configuration to use.

    <connectionstrings>
        <add name="ProductionDatabase" DataSource="production-db.mycompany.com" />
        <add name="TestDatabase" DataSource="test-db.mycompany.com" />
    </connectionstrings>
    

    However, if you don't want to do that, then you are welcome to write your own build/deployment scripts and have them do exactly what you want.