sateesh
sateesh

Reputation: 615

How to override the keys in windows services .exe.config file through VSTS release definition

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.

For creating the Windows Services Deploy task,I followed this Windows Services Extension

For example my drop folder looks like below:

enter image description here

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?

Upvotes: 3

Views: 386

Answers (1)

starian chen-MSFT
starian chen-MSFT

Reputation: 33728

You can use Tokenizer task in Release Management Utility tasks extension.

  1. Install Release Management Utility tasks extension
  2. Add Tokenizer with XPath/Regular expressions task to release definition (Specify Source filename and Configuration Json filename)

Config file sample:

<?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>

Configuration Json file (Default Environment is the environment name in release definitioin):

{
   "Default Environment":{
      "CustomVariables":{
         "Token2":"value_from_custom2",
         "Token3":"value_from_custom3"
      },
      "ConfigChanges":[
         {
            "KeyName":"/configuration/appSettings/add[@key='TestKey1']",
            "Attribute":"value",
            "Value":"value_from_xpath"
         }
      ]
   }
}

Then the value of 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.

On the other hand, you can use release variables directly if you don’t specify Configuration Json filename.

For example, there is __TokenVariable1__ in your config file and TokenVariable1 release/environment variable in release definition, then the __TokenVariable1__ will be replaced through Tokenizer task.

A related article: Using Tokenization (Token Replacement) for Builds/Releases in vNext/TFS 2015

Update:

You also can do it through PowerShell directly.

Update configuration files using PowerShell

Upvotes: 2

Related Questions