What's the best way to handle web.config file versions in ASP.Net?

一个人想着一个人 提交于 2020-01-04 05:11:51

问题


I have an ASP.Net web site (ASPX and ASMX pages) with a single web.config file. We have a development version and a production version. Over time, the web.config files for development and production have diverged substantially.

What is the best practice for keeping both versions of web.config in source control (we use Tortoise SVN but I don't think that matters)? It seems like I could add the production web.config file with a name like "web.config.prod", and then when we turnover all the files we would just add the step of deleting the existing web.config and renaming web.config.prod to web.config.

This seems hackish, although I'm sure it would work. Is there not some mechanism for dealing with this built in to Visual Studio? It seems like this would be a common issue, but I haven't found any questions (with answers) about this.


回答1:


We use the exact method you describe, it works great, for example we have:

  • web.config (for local development)
  • web.Dev.config (build server, builds on check-in)
  • web.QC.config (testing environment)
  • web.Prod.config (production)

The build script for each environment just deletes the web.config and renames the appropriate one in it's place. Doing this way allows you to easily source control all of them and very quickly do a diff and see what may be different between environments. Updating a config value across the board is much easier as well...the next time it's pushed to that environment, it'll get the new config.




回答2:


I use nant for my builds. On the SVN I have a web.config.template that contains parameters that are expanded using a properties file. Each environment has its own properties file with different values.

So in short, I don't have the web.config on the SVN, but a template instead.

Something like this

http://www.cptloadtest.com/2007/09/22/Managing-Multiple-Environment-Configurations-Through-NAnt.aspx

NAnt: http://nant.sourceforge.net/




回答3:


Visual Studio 2010 adds a new feature called XDT Transforms, which automatically combines multiple Web.config files for different configurations.

However, VS2008 does not include any such feature.



来源:https://stackoverflow.com/questions/2634596/whats-the-best-way-to-handle-web-config-file-versions-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!