如何通过 Azure DevOps 发布管道在 ClickOnce 应用程序上应用 XML 文件转换?

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

我的发布管道将应用程序部署到多个环境。

根据环境,我正在尝试设置要执行的文件转换,但我不确定如何设置它(如果可能的话)。我已经在存储库中设置了 app.Release.config 文件,但我不确定从这里去哪里。

在我的发布管道中,我启用了本机 XML 转换选项,但它实际上没有做任何事情。我还尝试添加文件转换任务并显式输入转换文件和 .exe.config 文件的路径,但也没有成功。我得到 "Unable to apply transformation for the given package."

与名字不匹配有关吗?因为这是一个 ClickOnce 应用程序,所以在编译时 app.config 的名称更改为 {nameOfApplication}.exe.config。我不知道如何完成我需要的东西,我开始认为这是不可能的?

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

File Transform task 如果我们能够满足其先决条件,那么它应该在您的场景中运行良好:

1.Make 确保转换文件(app.Release.config)和源文件({nameOfApplication}.exe.config)在同一路径中。

2.Make 请确保您的转换文件具有正确的 xdt 语法,sample 此处。

3.Choose 最新 2.0-preview 版本的文件转换任务,而不是 old 1.0

4.Try 在设置 Xml Transformation rules 时使用 有效 文件名。(使用 {nameOfApplication}.exe.config 而不是 *.exe.config

在我看来,上面的#1#3总是导致错误Unable to apply transformation for the given package的直接原因。仔细检查!

以上四个技巧的一些细节:

1.In 项目文件(xx.csproj) 我有此内容以确保将转换文件复制到输出文件夹。因此它将与源文件 xxx.exe.config.

位于同一文件夹中
<Content Include="App.release.config" >
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

2.My 测试 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>

我的测试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 修复了一些问题的最新版本:

4.According 对于某些测试,当您已经知道应用程序名称时,有效名称比 *.exe.config 这样的名称更有效:

希望以上对您有所帮助:)