xmlazure-devopsazure-pipelines-release-pipelinevariable-substitution

File-transform-task in Azure DevOps release-pipeline not substituting variables


In my project, there is a Webservice.settings containing 3 variables. (Structure of Webservice.settings) I intent to set these variables with my release-pipeline (Azure DevOps). Therefore, I created a variable-group in DevOps, containig the variables and the values I want to set. (Structure of variable-group) The variable-group was linked to the pipeline and its scope was set to "release".

To set the variables, the release-pipeline contains a file-transform-task. (Structure of file-transform-task

After the pipeline has run, the .exe.config looks like this:

  <applicationSettings>
    <MyFancyProgram.App.Properties.Webservice>
      <setting name="UrlEndpoint" serializeAs="String">
        </value>
      </setting>
      <setting name="LoginName" serializeAs="String">
        </value>
      </setting>
      <setting name="LoginPasswort" serializeAs="String">
        </value>
      </setting>
    </MyFancyProgram.App.Properties.Webservice>
  </applicationSettings>

The variables haven't been set.

My expectations were, that the .exe.config should have looked something like this:

  <applicationSettings>
    <MyFancyProgram.App.Properties.Webservice>
      <setting name="UrlEndpoint" serializeAs="String">
        <value>NoUrlEndpointNameSet</value>
      </setting>
      <setting name="LoginName" serializeAs="String">
        <value>NoLoginNameSet</value>
      </setting>
      <setting name="LoginPasswort" serializeAs="String">
        <value>NoLoginPasswortSet</value>
      </setting>
    </MyFancyProgram.App.Properties.Webservice>
  </applicationSettings>

What I've tried: I assumed, that I addressed the namespace inside the variable-group wrong. So inside the variable-group, I tried different options like:

https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/file-transform-v1?view=azure-pipelines https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/file-transform-v2?view=azure-pipelines


Solution

  • After some trial-and-error, coffee and a mild headache, I found the problem and solved it.

    I added some default-values to my Webservice.settings (Added values via designer)

    This lead to a slightly different structure in my .exe.config:

    <MyFancyProgram.App.Properties.Webservice>
      <setting name="UrlEndpoint" serializeAs="String">
        <value>someValue</value>
      </setting>
      <setting name="LoginName" serializeAs="String">
        <value>defaultPlaceholderLoginName</value>
      </setting>
      <setting name="LoginPasswort" serializeAs="String">
        <value>defaultPlaceholderLoginPasswort</value>
      </setting>
    </MyFancyProgram.App.Properties.Webservice>
    

    The important part here is, that for each variable-value there is now an opening- and closing-tag.

    <value>someValue</value>
    

    Before, there was only a "two in one"-tag.

    <value/>
    

    It looks like the file-transform-task performs its variable substitution only inside opening- and closing-value-tags and not inside "two in one"-value-tags.

    Appendum: A whitespace as default-value doesn't suffice to replace the "two in one"-value-tags with a opening- and closing-value-tag-pair.