管理部署环境之间的复杂的Web.config文件 [英] Managing complex Web.Config files between deployment environments

查看:203
本文介绍了管理部署环境之间的复杂的Web.config文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道有任何好的工具/实用管理不同的生成/部署环境之间的 Web.config中文件?

Does anyone know of any good tools/utilities for managing Web.Config files between different build/deployment environments?

例如,我有一个在发展中,我不想启用SSL一个WCF项目,但我不希望它在生产中启用。我想不同的日志记录设置,不同的数据库连接字符串,不同的错误处理,不同的文件路径...甚至一些不同统一架构绑定(电线了嘲笑的单元测试,而不是用于部署的真实对象)。

For example, I have a WCF project that in development I don't want to enable SSL, but I do want it enabled in production. I want different logging settings, different DB connection strings, different error handling, different file paths... Even some different Unity framework bindings (wire up mocks for unit testing instead of the real objects for deployment).

维护 Web.config中个人副本是一种痛苦,因为添加一个新的Web服务是指编辑多个文件,并保持它们同步。

Maintaining individual copies of the Web.Config is a pain, because adding a new web service means editing multiple files and keeping them in sync.

我也注意到,如果你渣土与 Web.config中的手太多,Visual Studio会呛,如果您尝试使用添加项目向导,比方说,为WCF添加一个新的Web服务,因为它有修改Web.config添加的端点,第二不能分析它了。所以,我必须要小心,不要到现有的Web.Config无效。

I've also noticed that if you muck with the Web.Config too much by hand, Visual Studio will choke if you try to use the "add item" wizard to, say, add a new Web Service for WCF, since it has to modify the Web.Config to add the endpoint,a nd can't parse it any more. So I have to be careful not to invalidate the existing Web.Config.

我也想过只是用了一些正则表达式做替代品,只是建立在pre-build命令一个新的 Web.config中。这似乎是最好的选择,到目前为止...

I also thought about just using some regex to do replacements and just building a new Web.Config in a pre-build command. That seems like the best option so far...

任何其他的想法?看起来这应该是一个很常见的问题,因为 Web.config中可能应该永远不会开发和生产部署之间是相同的。

Any other ideas? It seems like this should be a very common issue, since the Web.Config should probably never be the same between development and production deployments.

更新:

Update:

我决定写一个快速的控制台应用程序,将采取所有的XML文件中给定的目录,并将它们合并成一个,只有基于名称包含某些文件。

I decided to write a quick console app that will take all the xml files in a given directory and merge them into one, and only include certain files based on the name.

因此​​,我可以在目录中进行:

So I can make in a directory:

WebConfig_All

<configuration>
  <configSections>
    ...
  </configSections>
  <system.web>
    ...
  </system.web>
</configuration>

connectionStrings_Debug

<configuration>
  <connectionStrings>
    <add name="connstr" connectionString="...dev..." />
  </connectionStrings>
</configuration>

connectionStrings_Release

<configuration>
  <connectionStrings>
    <add name="connstr" connectionString="...prod..." />
  </connectionStrings>
</configuration>

然后运行我的命令行工具,并通过在配置(调试,发布,自定义...) 它会合并所有的结束 _所有或 _&LT文件;结构&gt;`

Then run my command line tool, and pass in the configuration (Debug, Release, custom...) And it will merge all the files that end in _All" or_<configuration>`.

所以现在我有80%的web.config的我在一个单一的 WebConfig_All 的文件,并在每个构建配置单独的文件中的20%自定义的东西。然后我可以运行我的命令行工具,在VisualStudio中一个pre-建设任务,或恶性,或任何我想...

So now I have 80% of my Web.Config in a single WebConfig_All file, and the 20% custom stuff in separate files per build configuration. I can then run my command line tool as a pre-build task in VisualStudio, or from NAnt, or wherever I want...

我还做了我的XML合并逻辑不够好,处理的东西,如:

I also made my XML merge logic good enough to handle stuff like:

<x>
  <y a="1">
    <z a="1"/>
  </y>
</x>

与合并

<x>
  <y a="1">
    <z a="2"/>
  </y>
  <y a="2"/>
</x>

结果:

<x>
  <y a="1">
    <z a="1"/>
    <z a="2"/>
  </y>
  <y a="2"/>
</x>

看起来不错迄今为止...:)

Looking good so far... :)

跟帖:

这题目有点老了,所以我想指出的VisualStudio 2010具有的功能做的web.config转换内置:的 http://msdn.microsoft.com/en-us/vstudio/Video/ff801895

This topic is a little old now, so I wanted to point out that VisualStudio 2010 has a feature to do web.config transformations built-in: http://msdn.microsoft.com/en-us/vstudio/Video/ff801895

当然,只有实现任何功能的方式50%的典型的微软的时尚,它仅适用于使用Web部署Web项目。有一个插件,让在其他项目中,设在这里的转换:<一href="http://www.hanselman.com/blog/SlowCheetahWebconfigTransformationSyntaxNowGeneralizedForAnyXMLConfigurationFile.aspx" rel="nofollow">http://www.hanselman.com/blog/SlowCheetahWebconfigTransformationSyntaxNowGeneralizedForAnyXMLConfigurationFile.aspx

Of course in typical Microsoft fashion of only implementing any feature 50% of the way, it only works for web projects using web deploy. There is a plugin to enable transformations in other projects, located here: http://www.hanselman.com/blog/SlowCheetahWebconfigTransformationSyntaxNowGeneralizedForAnyXMLConfigurationFile.aspx

您也可以使用如 buildmaster的一个工具来管理配置文件(连同构建,测试,DB脚本等)

You could also use a tool like BuildMaster to manage config files (along with builds, tests, DB scripts, etc...)

推荐答案

我们打出了全区域的具体设置成thier自己的配置文件。在Web应用程序的根目录下,我们创建一个配置文件夹,并把该地区特定的设置在那里。所以,无论文件都生活在配置的根目录下将得到回升。

We split out all region specific settings into thier own config file. Under the root of the web app we create a config folder and place the region specific settings there. So whatever files are living under the root of config will get picked up.

我们的web.config文件看起来是这样的:

our web.config looks something like:

.
.
.
<appSettings configSource="config\appSettings.config"/>
<nlog configSource="config\nlog.config"/>
<applicationSettings>
	<MyApp.UI.Properties.Settings configSource="config\Settings.APGUI.config"/>
	<MyApp.BusinessServices.Properties.Settings configSource="config\Settings.Business.config"/>
	<MyApp.Auditing.Properties.Settings configSource="config\Settings.Auditing.config"/>
</applicationSettings>
.
.
.

因此​​,如果我们要部署到发布区域的构建工具只会有一个动作,以取代在配置与适当的区域文件夹中的文件的根目录中的文件。该文件的结构看起来是这样的:

So if we are deploying to the release region the build tool will just have an action to replace the files in the root of config with the files from the appropriate region folder. The file structure looks something like:

增加:这就是源头控制结构看,已部署的应用程序将只是有配置目录,没有子文件夹或课程

ADDED: This is how the source control structure looks, the deployed app would just have the config dir with no sub folders or course

\Root
   web.config    
   \Config    
       appsettings.config    
       services.config    
       logging.config    
       \release    
          appsettings.config    
          services.config    
          logging.config    
       \debug
          appsettings.config    
          services.config    
          logging.config

这是pretty的清洁,并支持任何自动生成工具(复制/替换文件)。在漂亮的侧面影响在于,开发人员可以创建不同的口味,让他们在源代码控制在不影响真实的configs。

It is pretty clean and supported by any automated build tool(copying/replacing files). The nice side affect is that developers can create different flavors and keep them under source control without affecting the "real" configs.

这篇关于管理部署环境之间的复杂的Web.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆