You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级FileTransform@2任务时JSON文件匹配异常问题

问题:FileTransform@2未匹配指定的jsonTargetFiles,反而用***.config模式匹配

我正尝试把构建管道里已弃用的FileTransform@1升级成FileTransform@2,配置如下:

- task: FileTransform@2
  displayName: 'Replace test app settings'
  inputs:
    folderPath: 'Dss.Test.Integration'
    jsonTargetFiles : 'appsettings.json'

运行任务后得到输出日志:

##[debug]check path : D:\a\_tasks\FileTransform_8ce97e91-56cc-4743-bfab-9a9315be5f27\2.244.1\node_modules\azure-pipelines-tasks-webdeployment-common\module.json
##[debug]adding resource file: D:\a\_tasks\FileTransform_8ce97e91-56cc-4743-bfab-9a9315be5f27\2.244.1\node_modules\azure-pipelines-tasks-webdeployment-common\module.json
##[debug]system.culture=en-US
##[debug]folderPath=D:\a\1\s\Dss.Test.Integration
##[debug]Finding files matching input: D:\a\1\s\Dss.Test.Integration
##[debug]xmlTransformationRules=-transform **\*.Release.config -xml **\*.config
##[debug]xmlTargetFiles=undefined
##[debug]jsonTargetFiles=appsettings.json
##[debug]defaultRoot: 'D:\a\1\s\Dss.Test.Integration'
##[debug]findOptions.allowBrokenSymbolicLinks: 'false'
##[debug]findOptions.followSpecifiedSymbolicLink: 'false'
##[debug]findOptions.followSymbolicLinks: 'false'
##[debug]findOptions.skipMissingFiles: 'undefined'
##[debug]matchOptions.debug: 'false'
##[debug]matchOptions.nobrace: 'true'
##[debug]matchOptions.noglobstar: 'false'
##[debug]matchOptions.dot: 'true'
##[debug]matchOptions.noext: 'false'
##[debug]matchOptions.nocase: 'true'
##[debug]matchOptions.nonull: 'false'
##[debug]matchOptions.matchBase: 'false'
##[debug]matchOptions.nocomment: 'false'
##[debug]matchOptions.nonegate: 'false'
##[debug]matchOptions.flipNegate: 'false'
##[debug]pattern: '**\*.config'
##[debug]findPath: 'D:\a\1\s\Dss.Test.Integration'
##[debug]statOnly: 'false'
##[debug]findPath: 'D:\a\1\s\Dss.Test.Integration'
##[debug]findOptions.allowBrokenSymbolicLinks: 'false'
##[debug]findOptions.followSpecifiedSymbolicLink: 'false'
##[debug]findOptions.followSymbolicLinks: 'false'
##[debug]findOptions.skipMissingFiles: 'undefined'
##[debug]  D:\a\1\s\Dss.Test.Integration (directory)
##[debug]  D:\a\1\s\Dss.Test.Integration\appsettings.json (file)
##[debug]  D:\a\1\s\Dss.Test.Integration\Dss.Test.Integration.csproj (file)
##[debug]  D:\a\1\s\Dss.Test.Integration\Infrastructure (directory)
##[debug]  D:\a\1\s\Dss.Test.Integration\Infrastructure\MerchantApi (directory)
##[debug]  D:\a\1\s\Dss.Test.Integration\Infrastructure\MerchantApi\MerchantApiTest.cs (file)
##[debug]  D:\a\1\s\Dss.Test.Integration\Infrastructure\Persistence (directory)
##[debug]  D:\a\1\s\Dss.Test.Integration\Infrastructure\Persistence\Repositories (directory)
##[debug]  D:\a\1\s\Dss.Test.Integration\Infrastructure\Persistence\Repositories\AccountMappingRepositoryTest.cs (file)
##[debug]  D:\a\1\s\Dss.Test.Integration\Infrastructure\Persistence\Repositories\BankPaymentRepositoryTest.cs (file)
##[debug]  D:\a\1\s\Dss.Test.Integration\Infrastructure\Persistence\Repositories\FundingFileRepositoryTest.cs (file)
##[debug]  D:\a\1\s\Dss.Test.Integration\Infrastructure\Persistence\Repositories\OnlinePaymentRepositoryTest.cs (file)
##[debug]  D:\a\1\s\Dss.Test.Integration\Infrastructure\Persistence\Repositories\PayoutRepositoryTest.cs (file)
##[debug]  D:\a\1\s\Dss.Test.Integration\Infrastructure\Persistence\Repositories\ReceivableRepositoryTest.cs (file)
##[debug]  D:\a\1\s\Dss.Test.Integration\PersistenceTest.cs (file)
##[debug]  D:\a\1\s\Dss.Test.Integration\RunnableInDebugOnly.cs (file)
##[debug]  D:\a\1\s\Dss.Test.Integration\Services (directory)
##[debug]  D:\a\1\s\Dss.Test.Integration\Services\PaymentJournalTest.cs (file)
##[debug]18 results
##[debug]found 18 paths
##[debug]applying include pattern
##[debug]adjustedPattern: 'D:\a\1\s\Dss.Test.Integration\**\*.config'
##[debug]0 matches
##[debug]0 final results
##[error]Unable to apply transformation for the given package - Changes are already present in the package.

我预期D:\a\1\s\Dss.Test.Integration\appsettings.json能被匹配,但任务似乎跳过了jsonTargetFiles参数,反而用了我没指定的**\*.config模式,这是为什么?

原因及解决方案

原因分析

FileTransform@2默认会启用XML转换逻辑,哪怕你只配置了JSON相关参数。日志里的xmlTransformationRules=-transform **\*.Release.config -xml **\*.config是任务内置的默认XML转换规则,当任务找不到匹配的.config文件时,会直接抛出错误,导致后续的JSON转换逻辑根本没机会执行。

解决方案

你需要明确禁用XML转换,让任务专注处理JSON文件,修改后的配置如下:

- task: FileTransform@2
  displayName: 'Replace test app settings'
  inputs:
    folderPath: 'Dss.Test.Integration'
    jsonTargetFiles: 'appsettings.json'
    enableXmlTransformation: false

添加enableXmlTransformation: false后,任务会跳过XML转换步骤,直接按照你指定的jsonTargetFiles去匹配文件,就能正确处理appsettings.json了。

另外,如果后续需要保留XML转换能力,但当前场景不需要,也可以设置xmlTargetFiles: ''(空值),避免任务使用默认的**\*.config规则去匹配文件。

内容的提问来源于stack exchange,提问作者Rasmus B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 14:07:34