How to apply XML File Transformations on a ClickOnce application through Azure DevOps release pipeline?
O

1

0

My release pipeline deploys the application to multiple environments.

Based on the environment, I am trying to set up File Transformations to be executed, though I'm not sure how to set it up, if at all possible. I already have the app.Release.config file set up in the repository, but I'm not sure where to go from here.

In my release pipelines, I've enabled the native XML Transformation option, but it doesn't actually do anything. I've also tried adding the File Transform task and explicitly inputted the paths to the transform file as well as the .exe.config file, but no luck either. I get "Unable to apply transformation for the given package."

Is it something to do with the mismatch in names? Because this is a ClickOnce application, at compile time the name of the app.config changes to {nameOfApplication}.exe.config. I'm lost at how to accomplish what I need, and I'm starting to think it isn't possible?

Omnidirectional answered 6/4, 2020 at 16:27 Comment(2)
Hi, could you share some details about how you define the File Transform task so that we can check it for you directly.Masto
Hi, so I've tried checking the option on the actual IIS deployment task, and I've also tried using the actual file transform task with the following pattern: "-transform App.Release.config -xml DepartmentAD.config(*.exe.config)"Omnidirectional
M
2

How to apply XML File Transformations on a ClickOnce application through Azure DevOps release pipeline?

File Transform task should work well in your scenario if we can meet its prerequisites:

1.Make sure the transform file(app.Release.config) and the source file({nameOfApplication}.exe.config) are in same path.

2.Make sure your transform file has correct xdt syntax, sample here.

3.Choose latest 2.0-preview version of File Transform task instead of old 1.0.

4.Try using valid file name when setting Xml Transformation rules.(Use {nameOfApplication}.exe.config instead of *.exe.config)

In my opinion, #1 and #3 above are always the direct cause of the error Unable to apply transformation for the given package. Check them carefully!

Some details for above four tips:

1.In project file(xx.csproj) I have this content to make sure the transform file will be copied to output folder. So it will be in same folder with source file xxx.exe.config.

<Content Include="App.release.config" >
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

2.My test App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
      <add key="IsPackage" value="false" />
    </appSettings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
    </startup>
</configuration>

My test App.release.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration  xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add xdt:Transform="Replace" xdt:Locator="Match(key)" key="IsPackage" value="true" />
  </appSettings>
</configuration>

3.Use latest version which fixes some issues:

enter image description here

4.According to some tests, valid name works better than something like *.exe.config when you already know the application name:

enter image description here

Hope all above helps :)

Masto answered 8/4, 2020 at 2:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.