'Error: XML transformation error in Azure Pipelines

I've spent the day trying to get to the bottom of an XML transformation error in Azure DevOps and I can't seem to get a handle on the problem. Locally the config transform works fine and the config transforms for the other environments that I'm deploying to are working in Azure DevOps.

The error that appears in the logs when the IIS Web App Deployment task is terminated is:

2021-02-26T15:29:49.9263250Z ##[error]Error: XML transformation error while transforming C:\...\Web.config using C:\...\Web.Live.config.

Obviously I've cut out the long file paths that Azure DevOps applies.

Further up in the IIS Web App Deployment task logs the following error appears but is not highlighted as being significant. Aster this error is logged it does appear to apply transforms, before giving the aforementioned error which terminates the process:

2021-02-26T15:29:49.9178971Z System.NullReferenceException: Object reference not set to an instance of an object.
2021-02-26T15:29:49.9180071Z    at Microsoft.Web.XmlTransform.XmlTransformationLogger.ConvertUriToFileName(XmlDocument xmlDocument)
2021-02-26T15:29:49.9180525Z    at Microsoft.Web.XmlTransform.XmlTransformationLogger.LogWarning(XmlNode referenceNode, String message, Object[] messageArgs)
2021-02-26T15:29:49.9180911Z    at Microsoft.Web.XmlTransform.Transform.ApplyOnAllTargetNodes()

I've been through the XML file and can't find any malformed XML, I've also run it through an XML validator. I've previewed the transform locally in Visual Studio 2019 Professional (possible using Slow Cheetah) and it's fine there too.

Can anyone give a pointer as to what might cause this transformation error in the pipelines?



Solution 1:[1]

I know this one is a bit old, but the problem could be that the VSBuild task is transforming the web.config file, and then the release pipeline is as well.

So for example, if you have a transform that removes the debug attribute, unless the VSBuild task has a TransformWebConfigEnabled=False parameter, it will transform the web.config and remove the debug attribute. When the release pipeline runs it will again try to remove the attribute, but it's already been removed, so the error is thrown.

Here's how I instruct the VSBuild task not to transform:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeremy