Managing web.config files

☆樱花仙子☆ 提交于 2019-12-04 06:46:29

Is there a way to make transformations work with a normal web publish?

Absolutely, take a look at this MSDN link. You do not need MSBUILD. You can set your connection strings for your various environments in separate config files. For example, you could have Web.config, Web.QA.config, and Web.Prod.config, where QA and Prod are separate Visual Studio Build configurations.

Alternatively, you could just use the build configurations that are added by default: Web.config (local development), Web.Debug.config (use for QA), and Web.Release.config (use for production).

Using this setup as an example, Web.config would have all configuration, Web.Debug.config would have only the config that changes for that environment (connection strings, app settings, etc), and Web.Release.config has only the config that changes for that environment.

Once your configs and transformations are setup, you just change your build configuration, build and publish from Visual Studio.

Do you have any alternative suggestions for managing 3 web.config files?

Yes, don't manage them. The less we manage, the less chances of making mistakes. Have exactly the same web.config files for all your environments. Same distributive package deployed everywhere.

And all environment specific keys such as base urls, connection strings, ... could be defined in machine.config which you deploy only once on each server and reused from all your applications. Or a web.config at the root of your IIS site which all applications would derive from.

If you use a websetup project to create an msi, you could add a custom installer class to websetup. This would give you the option of creating pre-defined batch scripts that would properly set the values in the web.config

msiexec.exe /Qb! /i "MyWebsiteMsi.MSI" SQL_SERVER_ConnStr="ABC" 

Here's some page with an old example enter link description here

An alternative is to create move your settings that change into an external file & link that file back in using the configSource attribute. For sections that differ you put that in an external file.

You can then either have separately named files, eg dev.config, qa.config, live.config & change the name in the web.config, or have 1 file say called environment.config & you never merge it between environments.

The downside is the whole setting section has to be moved into the file.

Simon

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