I use external config files for various dynamic sections in my web.config files. Essentially all the dynamic variables between environments (Prod, UAT, Test, Dev etc.) have been externalised out to generic named .config files.
我将外部配置文件用于web.config文件中的各种动态部分。基本上所有环境之间的动态变量(Prod,UAT,Test,Dev等)都已外部化为通用命名的.config文件。
My web.config is generic as well so all environments utilise the same web.config (as things like connection strings etc. are in the external files). All the files are named the same across the environments so when we do a release we just need to keep the web.config and \Configs* directory in tact during a release.
我的web.config也是通用的,因此所有环境都使用相同的web.config(因为连接字符串等都在外部文件中)。所有文件在整个环境中的命名都是相同的,因此当我们进行发布时,我们只需要在发布期间保持web.config和\ Configs *目录。
What I want to do (via something like XSLT or PowerShell) is to merge all of the information contained within these external *.config files back into the web.config so that I can compare the (now merged) web.config with the version provided by developers.
我想做的事情(通过XSLT或PowerShell之类的东西)将这些外部* .config文件中包含的所有信息合并回web.config,以便我可以将(现在合并的)web.config与版本进行比较由开发人员提供。
So our present web.config may say:
所以我们现在的web.config可能会说:
<sessionState configSource="Configs\System.Web.SessionStateConnectionString.config" />
And in the System.Web.SessionStateConnectionString.config file for the Prod environment has:
在Prod环境的System.Web.SessionStateConnectionString.config文件中有:
<sessionState mode="StateServer" cookieless="true" timeout="20"/>
And for the Test environment has:
而对于测试环境有:
<sessionState mode="InProc" cookieless="true" timeout="20"/>
I'd like to merge in all the external *.config files back into a web.config so that the file is essentially completed as if configSource had never been used. This will allow me to perform a diff or WinMerge on the web.config file (after it's been merged back) and what the developer gives us, showing which things have been changed such as new keys added or new modules utilised.
我想将所有外部* .config文件合并回web.config,以便该文件基本上完成,就像从未使用过configSource一样。这将允许我在web.config文件上执行diff或WinMerge(在它被合并之后)以及开发人员给我们的内容,显示哪些内容已被更改,例如添加了新密钥或使用了新模块。
What would be the best way of going about this?
怎样才能解决这个问题?
1 个解决方案
#1
0
I don't have a simple approach. I do hope there is one exist and it would help both of us.
我没有一个简单的方法。我希望有一个存在,这将有助于我们两个人。
I found the only reliable way of modifying a large amount of config file during deployment without mistake is do the actual XML editing. Which means follow the XML structure.
我发现在部署过程中唯一可靠的修改大量配置文件的方法就是进行实际的XML编辑。这意味着遵循XML结构。
With that, the task you are trying to archive, is not only changing a XML value
这样,您尝试归档的任务不仅仅是更改XML值
From
<sessionState configSource="Configs\System.Web.SessionStateConnectionString.config" />
To
<sessionState configSource="abc.config" />
but also changing XML parent's name
但也改变XML父母的名字
From
<sessionState configSource="abc.config" />
To
<sessionState mode="stateServer" />
Then, you need attach more child to make it
然后,你需要附加更多的孩子来做它
<sessionState mode="StateServer" cookieless="true" timeout="20"/>
Thus, I saved all environmental variables I need in a deployment tool, instead of using another XML for comparsion. During deployment, my deployment script (powershell) directly load the config file $config = [xml](get-content $webconfig)
and load the variables from deployment tool
因此,我在部署工具中保存了我需要的所有环境变量,而不是使用另一个XML进行比较。在部署期间,我的部署脚本(powershell)直接加载配置文件$ config = [xml](get-content $ webconfig)并从部署工具加载变量
For a simple change I would do
我会做一个简单的改变
$node = $config.configuration.sessionState | where {$_.configSource -eq 'Configs\System.Web.SessionStateConnectionString.config'}
$node.configSource = $Prod_session_config #"abc.config"
For the change you need, I will detach configSource
from sessionState
and reattach 3 new child mode
, cookieless
, timeout
with their desired value.
对于您需要的更改,我将从sessionState分离configSource并重新连接3个新的子模式,无cookie,超时及其所需的值。
With that said, this is a very lengthy deployment script. You can create your own helpers to make it look much better, something like replace-config $config_keyname $config_keyvalue
. Even with helpers to reduce common operations you need, this is still easily thousands line of code depending on how many moving parts your application have.
话虽如此,这是一个非常冗长的部署脚本。您可以创建自己的帮助程序,使其看起来更好,例如replace-config $ config_keyname $ config_keyvalue。即使使用帮助程序来减少您需要的常见操作,根据应用程序的移动部件数量,这仍然可以轻松实现数千行代码。
This would probly take weeks to accomplish. Once this is done, there is unlikely any massive changes to it but still require you to have very good communication with developers, you need them to update you whenever a new environment dependent variable is introduced.
这可能需要数周才能完成。完成此操作后,不太可能对其进行任何大的更改,但仍需要您与开发人员进行非常好的通信,每当引入新的环境因变量时,您需要他们更新您。
This task can also be done with configuration management tools like Puppet Augeas, but I don't think that's any easier if you write down a few good helpers in powershell. I looked into XSLT as well but couldn't find a convenient way to use it with my deployment tool.
这个任务也可以使用像Puppet Augeas这样的配置管理工具来完成,但是如果你在PowerShell中写下一些好帮手,我认为这并不容易。我也查看了XSLT,但找不到一种方便的方法来将它与我的部署工具一起使用。
This is my solution with limited devops experience and I desperately hope there would be a better one same as you do.
这是我的解决方案,有限的devops经验,我非常希望有一个更好的一个与你一样。
#1
0
I don't have a simple approach. I do hope there is one exist and it would help both of us.
我没有一个简单的方法。我希望有一个存在,这将有助于我们两个人。
I found the only reliable way of modifying a large amount of config file during deployment without mistake is do the actual XML editing. Which means follow the XML structure.
我发现在部署过程中唯一可靠的修改大量配置文件的方法就是进行实际的XML编辑。这意味着遵循XML结构。
With that, the task you are trying to archive, is not only changing a XML value
这样,您尝试归档的任务不仅仅是更改XML值
From
<sessionState configSource="Configs\System.Web.SessionStateConnectionString.config" />
To
<sessionState configSource="abc.config" />
but also changing XML parent's name
但也改变XML父母的名字
From
<sessionState configSource="abc.config" />
To
<sessionState mode="stateServer" />
Then, you need attach more child to make it
然后,你需要附加更多的孩子来做它
<sessionState mode="StateServer" cookieless="true" timeout="20"/>
Thus, I saved all environmental variables I need in a deployment tool, instead of using another XML for comparsion. During deployment, my deployment script (powershell) directly load the config file $config = [xml](get-content $webconfig)
and load the variables from deployment tool
因此,我在部署工具中保存了我需要的所有环境变量,而不是使用另一个XML进行比较。在部署期间,我的部署脚本(powershell)直接加载配置文件$ config = [xml](get-content $ webconfig)并从部署工具加载变量
For a simple change I would do
我会做一个简单的改变
$node = $config.configuration.sessionState | where {$_.configSource -eq 'Configs\System.Web.SessionStateConnectionString.config'}
$node.configSource = $Prod_session_config #"abc.config"
For the change you need, I will detach configSource
from sessionState
and reattach 3 new child mode
, cookieless
, timeout
with their desired value.
对于您需要的更改,我将从sessionState分离configSource并重新连接3个新的子模式,无cookie,超时及其所需的值。
With that said, this is a very lengthy deployment script. You can create your own helpers to make it look much better, something like replace-config $config_keyname $config_keyvalue
. Even with helpers to reduce common operations you need, this is still easily thousands line of code depending on how many moving parts your application have.
话虽如此,这是一个非常冗长的部署脚本。您可以创建自己的帮助程序,使其看起来更好,例如replace-config $ config_keyname $ config_keyvalue。即使使用帮助程序来减少您需要的常见操作,根据应用程序的移动部件数量,这仍然可以轻松实现数千行代码。
This would probly take weeks to accomplish. Once this is done, there is unlikely any massive changes to it but still require you to have very good communication with developers, you need them to update you whenever a new environment dependent variable is introduced.
这可能需要数周才能完成。完成此操作后,不太可能对其进行任何大的更改,但仍需要您与开发人员进行非常好的通信,每当引入新的环境因变量时,您需要他们更新您。
This task can also be done with configuration management tools like Puppet Augeas, but I don't think that's any easier if you write down a few good helpers in powershell. I looked into XSLT as well but couldn't find a convenient way to use it with my deployment tool.
这个任务也可以使用像Puppet Augeas这样的配置管理工具来完成,但是如果你在PowerShell中写下一些好帮手,我认为这并不容易。我也查看了XSLT,但找不到一种方便的方法来将它与我的部署工具一起使用。
This is my solution with limited devops experience and I desperately hope there would be a better one same as you do.
这是我的解决方案,有限的devops经验,我非常希望有一个更好的一个与你一样。