如何通过VSTS版本定义覆盖Windows Services .exe.config文件中的键 [英] How to override the keys in windows services .exe.config file through VSTS release definition
问题描述
我正在处理用于部署Windows Services Project的VSTS发布任务.不幸的是,我们没有为创建放置文件夹创建任何构建定义. 但是,我的客户将为此项目提供放置文件夹,我需要的是发布级别的我想覆盖现有.exe.config文件的键".
I am working on VSTS release task for deploying the Windows Services Project. Unfortunately, we are not creating any Build Definition for creating drop folder. But, my client will provide drop folder for this project, what I need is "I want to override the keys of an existing .exe.config file" at release level.
对于创建Windows Services部署任务,我遵循了以下 Windows服务扩展程序
For creating the Windows Services Deploy task,I followed this Windows Services Extension
例如,我的放置文件夹如下所示:
For example my drop folder looks like below:
非常感谢您提供此参考资料 article ,这对于使用Power Shell命令更改配置文件中的值非常有用.我对此参考链接表示怀疑: 例如,如果有这样的代码:
Many thanks for this reference article and It's a very useful for changing values in config file using Power Shell commands. I have doubt in from that reference link : For Example, If had a Code like this :
<erecruit.tasks>
<tasks>
<task name="AA" taskName="AA">
<parameters>
<param key="connectionString">Server="XXXX"</param>
</parameters>
</task>
如何更改上面的连接字符串值?
How to change this above connectionstring value?
推荐答案
您可以在
配置文件示例: 配置Json文件(默认环境是发行版definitioin中的环境名称): Configuration Json file (Default Environment is the environment name in release definitioin): 然后 Then the value of 另一方面,如果您未指定Configuration Json文件名,则可以直接使用发布变量. On the other hand, you can use release variables directly if you don’t specify Configuration Json filename. 例如,您的配置文件中有 For example, there is 相关文章:更新: 您还可以直接通过PowerShell进行操作. You also can do it through PowerShell directly. 这篇关于如何通过VSTS版本定义覆盖Windows Services .exe.config文件中的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TestKey1" value="__Token1__" />
<add key="TestKey2" value="__Token2__" />
<add key="TestKey3" value="__Token3__" />
<add key="TestKey4" value="__Token4__" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
{
"Default Environment":{
"CustomVariables":{
"Token2":"value_from_custom2",
"Token3":"value_from_custom3"
},
"ConfigChanges":[
{
"KeyName":"/configuration/appSettings/add[@key='TestKey1']",
"Attribute":"value",
"Value":"value_from_xpath"
}
]
}
}
TestKey1
(键)的值将与value_from_xpath
相关,而TestKey2
和TestKey3
的值将与value_from_custom2
和value_from_custom3
相关.TestKey1
(key) will be related to value_from_xpath
and the values of TestKey2
and TestKey3
will be related to value_from_custom2
and value_from_custom3
.__TokenVariable1__
,发行版本定义中有TokenVariable1
release/environment变量,则__TokenVariable1__
将通过 Tokenizer 任务替换.__TokenVariable1__
in your config file and TokenVariable1
release/environment variable in release definition, then the __TokenVariable1__
will be replaced through Tokenizer task.