如何通过Azure DevOps发布管道在ClickOnce应用程序上应用XML文件转换? [英] How to apply XML File Transformations on a ClickOnce application through Azure DevOps release pipeline?

查看:136
本文介绍了如何通过Azure DevOps发布管道在ClickOnce应用程序上应用XML文件转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My release pipeline deploys the application to multiple environments.

基于环境,我试图设置要执行的文件转换,尽管我不确定如何设置它(如果可能的话).我已经在存储库中设置了app.Release.config文件,但是我不确定从这里开始.

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.

在我的发布管道中,我启用了本机XML转换选项,但实际上并没有执行任何操作.我还尝试添加文件转换任务,并明确输入转换文件以及.exe.config文件的路径,但也没有运气.我得到无法对给定的包应用转换".

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."

与名称不匹配有关吗?由于这是一个ClickOnce应用程序,因此在编译时app.config的名称将更改为{nameOfApplication} .exe.config.我迷失了如何完成我所需要的,而我开始认为这是不可能的?

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?

推荐答案

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

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.确保转换文件(app.Release.config)和源文件({name.Application.exe.config)位于同一路径.

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

2.确保您的转换文件具有正确的xdt语法,

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

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

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

4.设置Xml Transformation rules时,尝试使用有效文件名.(使用{nameOfApplication}.exe.config代替*.exe.config)

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

我认为,上面的#1#3始终是错误Unable to apply transformation for the given package的直接原因.仔细检查!

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!

以上四个提示的一些详细信息:

1.在项目文件(xx.csproj)中,我具有此内容,以确保将转换文件复制到输出文件夹.因此它将与源文件xxx.exe.config放在同一文件夹中.

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.我的测试App.config:

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>

我的测试App.release.config:

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.使用最新版本解决了一些问题:

3.Use latest version which fixes some issues:

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

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

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

Hope all above helps :)

这篇关于如何通过Azure DevOps发布管道在ClickOnce应用程序上应用XML文件转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆