2

I've got a simple ASP.NET MVC website. It has Debug, Testing and Release configuration modes.

We're using TFS as our source control and bug tracking, etc. Nice.

Now, we're about to embark on using Team Builds to automate some Continuous Intergration. The thing is, we're not sure how to make it so that if we want to make a DEBUG build, or a RELEASE build, it also drops the correct web.config file into the destination directory. Also, we have certain sections of the web.config file extracted to seperate files (eg. the connection string section or the machine key section, etc). Can the correct environment files be dropped correctly into the destination directory.

Pure.Krome
  • 84,693
  • 113
  • 396
  • 647

3 Answers3

3

You could do a pre-build step

Say you have checked in

  • /Debug.Web.Config
  • /Release.Web.Config

You could write a pre-build step to check the build type and copy the proper .config file to

  • /Web.Config

Something like

cp $(ConfigurationName).Web.Config $(TargetDir)

On a side note, ASP.net 4.0 will have support for multiple Web.Configs

http://weblogs.asp.net/gunnarpeipman/archive/2009/06/03/visual-studio-2010-multiple-web-config-versions.aspx

TJB
  • 13,367
  • 4
  • 34
  • 46
  • 1
    Love the new stuff coming in VS2010, etc :) With your idea above, this just copies our file OVER the web.config file in the destination (using cp command) so the original web.config is not messed with, right? – Pure.Krome Sep 17 '09 at 02:32
  • Yeah, i guess this way you wouldn't even have a web.config in your project, there would just be debug.web.config and release.web.config and then whenever you build the proper web config would be put in its place. But yes, your source web config shouldn't get messed with ;) of course this isn't tested so make sure everything is going in the right directories and what not. – TJB Sep 17 '09 at 06:04
  • Visual Studio 2014 is comming out and muti webconfig for local devs is still no supported. what a ball ache – Piotr Kula Nov 10 '14 at 14:45
2

Incidentally, using either a pre-build or post-build step will not work under Team Foundation Server. It automatically configures security on the build directory to prevent any changes being made to configuration files during the build process, whether as pre-build events or as post-build events. The only result of using cp is to return an "Access denied" error.

1

Look into config transforms. http://msdn.microsoft.com/en-us/library/dd465326.aspx

Ryan Cromwell
  • 2,613
  • 1
  • 17
  • 33