文件转换任务无法转换压缩包上的XML配置 [英] File Transform task fails to transform XML configurations on zipped package
问题描述
我正在开发发布管道,该管道将对App Service Worker配置进行转换,然后发布worker + Web应用.
I'm working on Release pipeline, which will perform transformation on App Service Worker configs, then will publish workers + web application.
我的输入包是一个MsBuild发布(从ASP.NET构建管道)产生的zip包.
My input package is a zip package produced out of MsBuild publish (from ASP.NET build pipeline).
...\PackageTmp\app_data\jobs\triggered\BillingWorker\App.Prod.config
...\PackageTmp\app_data\jobs\triggered\BillingWorker\App.Test.config
...\PackageTmp\app_data\jobs\triggered\BillingWorker\BillingWorker.exe.config
...\PackageTmp\app_data\jobs\triggered\EtlWorker\App.Prod.config
...\PackageTmp\app_data\jobs\triggered\EtlWorker\App.Test.config
...\PackageTmp\app_data\jobs\triggered\EtlWorker\EtlWorker.exe.config
...\PackageTmp\Web.config
...\PackageTmp\Web.Test.config
...\PackageTmp\Web.Prod.config
...\PackageTmp\many other files
通过Publish to Azure Web App
任务正确完成了Web.config
的转换.但是,工作程序配置不会自动转换,因此我使用以下配置添加了File Transform
任务:
Transformation of Web.config
is done correctly by Publish to Azure Web App
task. However, workers configs aren't transformed automatically, so I added a File Transform
task with following config:
此步骤不起作用,这是输出:
This step doesn't work and here is the output:
2019-08-14T15:41:01.1435779Z ##[section]Starting: File Transform: config
2019-08-14T15:41:01.1576716Z ==============================================================================
2019-08-14T15:41:01.1576853Z Task : File transform
2019-08-14T15:41:01.1576932Z Description : Replace tokens with variable values in XML or JSON configuration files
2019-08-14T15:41:01.1576994Z Version : 1.156.0
2019-08-14T15:41:01.1600786Z Author : Microsoft Corporation
2019-08-14T15:41:01.1600885Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/file-transform
2019-08-14T15:41:01.1600986Z ==============================================================================
2019-08-14T15:41:01.6339900Z ##[warning]Unable to apply transformation for the given package. Verify the following.
2019-08-14T15:41:01.6351367Z ##[warning]Unable to apply transformation for the given package. Verify the following.
2019-08-14T15:41:01.8369297Z Initiated variable substitution in config file :
...
... many lines about variable subsitution
...
此输出看起来不正确,因为它会产生警告,而没有声明的解释.如何解决此警告?
This output looks wrong, as it produces warning without declared explanation. How to workaround this warning?
推荐答案
问题是文件转换任务无法转换名称违反约定的文件:Name.Debug.xml -> Name.xml
The problem is that File Transform task fails to transform files with names breaking the convention: Name.Debug.xml -> Name.xml
App.config
文件在构建过程中被重命名为{YourApplicationName}.exe.config
.由于某些原因,使用App.Debug.config
对重命名的文件应用转换失败.
App.config
file is renamed to {YourApplicationName}.exe.config
during build. Applying tranformation on renamed file using App.Debug.config
fails for some reason.
我看到2种解决方法:
-
保留原始名称
App.config
a.将App.config
文件的属性设置为Copy to output directory: Copy always
a. Set App.config
file's property to Copy to output directory: Copy always
b.运行文件转换任务-transform *.Debug.config -xml *.config -result {YourApplicationName}.exe.config
b. Run File Transform task -transform *.Debug.config -xml *.config -result {YourApplicationName}.exe.config
c(可选).如果未在任务中指定-result
,则需要在转换完成后(使用Powershell)将App.config重命名为{YourApplicationName}.exe.config
.
c (optional). If you didn't specify -result
in task, you need to rename App.config to {YourApplicationName}.exe.config
after transformation finished (using Powershell).
编写自己的转化器
a.将包解压缩到临时文件夹中
a. Unzip package into temp folder
b.使用Powershell转换文件(利用代理上安装的Microsoft.Web.XmlTransform.dll)
b. Transform file using Powershell (make use of Microsoft.Web.XmlTransform.dll installed on agent)
b.再次压缩并替换原始拉链.
b. Zip again and replace original zip.
这篇关于文件转换任务无法转换压缩包上的XML配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!