Igor Kondrasovas
Igor Kondrasovas

Reputation: 1681

How to fix YAML File Transform Task when "changes are already present"?

We are starting with Azure Pipelines (YAML) and we are experiencing the following error during a FileTransform task:

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

The result is that no transformation is taking place and the deployed config matches the Release.config

This is an ASP.NET web app with a Web.Config, Web.Stage.config, Web.Release.config etc.

The end goal is to set different stages and apply the corresponding transformations with the config files. But for now, I just would like to get the "Release" build and apply the "Stage" transformation, to make sure this task works.

If it helps, this is a snippet of the 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'

Update: The final web.config file contains a connection string like this:

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

Here is the log for the build step. You can see transformaton is hapenning during build.

Here is the log for the build step. What am I missing here?

Thanks!

Upvotes: 2

Views: 4603

Answers (1)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30353

I tested and found above error will occur in below cases.

1, When no configuration file or transform file were found against the file pattern in xmlTransformationRules. This could be the file pattern is incorrect or the transform file/configuration file does not exist in the package.

2, When the configuration file and transform file are not in the same folder within the specified package.

The xmlTransformationRules in above yaml was working in my test. So you need to check if configuration file and transform file are in different folders. You need to make sure they are in the same folder for XML transformation to take effect.

See the XML transformation notes for more information.

Update:

By default web.config file will be transformed against the web.{buildConfiguration}.config during building.

You can disable vsbuild task to transform web.config by passing /p:IsTransformWebConfigDisabled=true to msbuildArgs attribute. See below example:

- 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)'

Upvotes: 1

Related Questions