It is possible to have different web.config files for a Team Foundation Server project?
-
07-07-2019 - |
Question
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.
Solution
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
OTHER TIPS
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.
Look into config transforms. http://msdn.microsoft.com/en-us/library/dd465326.aspx