0

I have been working on the build and release pipelines for a while now, but ran into this issue lately

I am performing config transform on .net application. The issue i am running into is a bit strange .. Variable substitution doesn’t work if xml transformation is enabled too, but will work ONLY when variable substitution is enabled. I didn't knew this was possible, as per me Variable substitution would work after XML transformation is done. I want to use both the options. Like i want to transform the existing config file and then substitute the remaining values with pipeline variables & variable groups. That way i would have less involvement from other teams to get the transformation for all the values as i have a time crunch. Eventually would have everything transformed but for now i want to follow the above approach. The log does say Xml transformation and Variable substitution completed successful, but variable substitution doesn't happen.

Am i missing something very silly? Has anyone faced this kind of issue.

enter image description here

AnsibleUser
  • 65
  • 1
  • 8
  • any pointers please? still stuck at this issue. – AnsibleUser Jul 27 '20 at 05:12
  • From the screenshot , it seems that you are using the `IIS web app deploy` task. If yes, you could check the `_temp `folder during the process of deployment. The conversion happens in this folder. You could refer to the answer. If there is any misunderstanding, please correct me. – Kevin Lu-MSFT Jul 27 '20 at 05:52

1 Answers1

0

Based on my test, XML variable substitution and XML transformation could work at the same time.

Here is the original web.config file:

enter image description here

Check the log, the transformation occurred in the _temp folder instead of the $(System.DefaultWorkingDirectory) (e.g. I use deployment group to run the task, so the $(System.DefaultWorkingDirectory) path is C:\azagent\A18\_work\r4\a).

enter image description here

In the temp folder, I noticed that the file has been transformed successfully.

enter image description here

If the object you deploy is a folder, then this transformation can only be found in the temp folder. After the deployment, the contents of this folder will be automatically deleted after deployment.

If the object you deploy is a zip file, in addition to the temp folder, a zip will be automatically generated in the $(System.DefaultWorkingDirectory) path, and the web.config file in this zip is also successfully transformed.

enter image description here

enter image description here

Update:

Here are some details:

Files:(web.config and web.qa.config)

enter image description here

Web.config:

  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PCWSUser" value="TheUserName" />
  </appSettings>

Web.qa.config:

  <appSettings>
    <add xdt:Transform="Replace" xdt:Locator="Match(key)" key="webpages:Enabled" value="true" />
    <add key="PCWSUser" value="TheUserNameQA" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
  </appSettings>

Release Pipeline variables:

enter image description here

Task settings:

enter image description here

Summary: the webpages:Version is changed by variable substitution. The others are changed by xml transformation.

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • Thanks Kevin for the response, This doesn't really say if the transformation happ due to xml or variable. Few quick questions. Did you select both the options in the pipeline i.e. xml and var and did you have the transform file in the same location i.e. web.qa.config etc ... can you specify which values were changed due to XML transformation and which ones were changed due to variable substitution. – AnsibleUser Jul 28 '20 at 22:14
  • Hi @AnsibleUser. Please check the update. I have shared some details about the your questions. – Kevin Lu-MSFT Jul 29 '20 at 01:00
  • Thanks Kevin for clarity, the only difference i see is the variables in the config are mutually exclusive i.e.the keys cannot be present in both the locations i.e. transform and var. If they are, then transform one takes precedence. I was under assumption first transform happens and then it is overwritten by variable substitution. Will try that out. Thanks again Kevin. – AnsibleUser Jul 30 '20 at 18:03
  • Yes. You are right. The XML transformation runs before variable transformation . So if the variable is defined in xx.qa.config and variable, it will eventually be replaced by the value in variable. – Kevin Lu-MSFT Jul 31 '20 at 01:07
  • @AnsibleUser. If the answer could give you some help, you may consider [accepting it as answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). Thanks. – Kevin Lu-MSFT Jul 31 '20 at 01:08
  • I did debug runs and found parsing error .. unfortunately it doesn't tell the parsing error for web.config file ...It just gives this error ... 2020-08-14T23:46:56.6511657Z ##[debug]Detecting file encoding using BOM 2020-08-14T23:46:56.6712776Z ##[debug]Unable to parse file : D:\Non-Deploy\TFSAgentazagent\A3\_work\_temp\temp_web_package_34975992642936804\Web.config 2020-08-14T23:46:56.6713097Z ##[debug]Error: Incomplete document – AnsibleUser Aug 14 '20 at 23:58
  • I think i figured out the issue. The issue was due to CData tag in teh config file. After that was removed from Web.config as well as from the Transform config, both the options seems to be working. Will need to test more. – AnsibleUser Aug 17 '20 at 07:15