CameronWills / FatAntelope

A tool for comparing .NET .config files and generating a config transform (Microsoft Xml Document Transform).
Other
85 stars 20 forks source link

remove namespace xdt did not work #8

Open chucklu opened 6 years ago

chucklu commented 6 years ago

I have base.xml and target.xml, and I want to apply the target to base. 1.base.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <appSettings>
    <add key="test20180523" value="1" />
  </appSettings>
</configuration>

2.target.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appSettings>
    <add key="test20180523" value="1" />
  </appSettings>
</configuration>

3.patch file

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" xdt:Transform="RemoveAttributes(xmlns)" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" />

4.nothing happened when I apply the patch to the source.

chucklu commented 6 years ago

It seems like a bug in Microsoft.Web.XmlTransform, I will look into it. the log info I got from Microsoft.Web.XmlTransform

Executing RemoveAttributes (transform line 1, 76) on /_defaultNamespace:configuration Applying to 'configuration' element (source line 2, 2) patch20180523104824805.config (1, 76) warning: Argument 'xmlns' did not match any attributes base.xml (2, 2) warning: No attributes found to remove Done executing RemoveAttributes

chucklu commented 6 years ago

I have found bug in AttributeTransform class of Microsoft.Web.Xdt

private XmlNodeList GetAttributesFrom(XmlNode node, IList<string> arguments, bool warnIfEmpty) {
            string[] array = new string[arguments.Count];
            arguments.CopyTo(array, 0);
            string xpath = String.Concat("@", String.Join("|@", array));

            XmlNodeList attributes = node.SelectNodes(xpath);
            if (attributes.Count == 0 && warnIfEmpty) {
                Debug.Assert(arguments.Count == 1, "Should only call warnIfEmpty==true with one argument");
                if (arguments.Count == 1) {
                    Log.LogWarning(SR.XMLTRANSFORMATION_TransformArgumentFoundNoAttributes, arguments[0]);
                }
            }

            return attributes;
        }

XmlNodeList attributes = node.SelectNodes(xpath); The SelectNodes did not consider the node could have xmlnamespace.