当“更改已存在”时,如何解决YAML文件转换任务?

时间:2020-06-01 07:35:21

标签: azure-devops yaml azure-pipelines

我们从Azure Pipelines(YAML)开始,在FileTransform任务过程中遇到以下错误:

##[error]Unable to apply transformation for the given package - Changes are already present in the package.

结果是不进行任何转换,并且已部署的配置与Release.config匹配

这是具有Web.Config,Web.Stage.config,Web.Release.config等的ASP.NET Web应用程序。

最终目标是设置不同的阶段,并对配置文件应用相应的转换。但是,现在,我只想获得“发布”版本并应用“阶段”转换,以确保此任务有效。

如果有帮助,这是YAML的摘要:

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

...

task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

...

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

- task: FileTransform@2
  inputs:
    folderPath: '$(Build.ArtifactStagingDirectory)/**/*.zip'
    xmlTransformationRules: '-transform **\*.Stage.config -xml **\*.config'

- task: AzureRmWebAppDeployment@4
  inputs:
    ConnectionType: 'AzureRM'
    azureSubscription: 'Microsoft Partner Network(blablabla)'
    appType: 'webApp'
    WebAppName: 'mywebapp'
    packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.zip'

更新: 最终的web.config文件包含这样的连接字符串:

<add name="DefaultConnection" connectionString="$(ReplacableToken_DefaultConnection-Web.config Connection String_0)" providerName="System.Data.SqlClient"/>

这是构建步骤的日志。您可以看到构建过程中转换发生了变化。

Here is the log for the build step. 我在这里想念什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

我进行了测试,发现在以下情况下会发生上述错误。

1,当针对xmlTransformationRules中的文件模式未找到配置文件或转换文件时。这可能是文件模式不正确或转换文件/配置文件在软件包中不存在。

2,当配置文件和转换文件不在指定软件包中的同一文件夹中时。

上面的yaml中的xmlTransformationRules在我的测试中正常工作。所以你需要检查 配置文件和转换文件位于不同的文件夹中。您需要确保它们在同一文件夹中,XML转换才能生效。

有关更多信息,请参见XML transformation notes

更新

默认情况下,在构建期间,将针对web。{buildConfiguration} .config转换web.config文件。

您可以通过将/p:IsTransformWebConfigDisabled=true传递给msbuildArgs属性来禁用vsbuild任务来转换web.config。参见以下示例:

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:IsTransformWebConfigDisabled=true /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'