Visual Studio Team Services web.config transform error

I have a transform that previews fine in Visual Studio but fails when the release is deployed.

I was getting the following error when deploying a web site using Release Management in Visual Studio Team Services:

Here is extract from the log file:

2017-06-05T10:53:08.5853655Z System.NullReferenceException: Object reference not set to an instance of an object.
2017-06-05T10:53:08.5853655Z    at Microsoft.Web.XmlTransform.XmlTransformationLogger.ConvertUriToFileName(XmlDocument xmlDocument)
2017-06-05T10:53:08.5853655Z    at Microsoft.Web.XmlTransform.XmlTransformationLogger.LogWarning(XmlNode referenceNode, String message, Object[] messageArgs)
2017-06-05T10:53:08.5853655Z    at Microsoft.Web.XmlTransform.Transform.ApplyOnAllTargetNodes()
2017-06-05T10:53:08.6012521Z [command]C:\vstsagent\A1\_work\_tasks\IISWebAppDeploymentOnMachineGroup_1b467810-6725-4b6d-accd-886174c09bba\0.0.17\ctt\ctt.exe  ... etc etc ....

I tracked that the culprit was the following transform:


<system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>

I got it to work by changing the transform to this:


 <system.web>
    <compilation targetFramework="4.5" xdt:Transform="Replace">
    </compilation>
 </system.web>