Removing XML Comments Using Visual Studio 2010 Web Config Conversion

We use Team Build to handle our deployments on our development server, and we need to remove comments from our web configuration when it is being converted. Does anyone know how to remove comment lines <!-- -->from a web config file using conversion?

+5
source share
3 answers

I have found the answer. This seems to be a known bug in the XDT to Visual Studio / Team Build conversion engine. This error was reported in March, so I do not know when it will be fixed.

Here is the link

: . , -. , , .

+3

. -:

public static string RemoveComments(
        string xmlString,
        int indention,
        bool preserveWhiteSpace)
    {
        XmlDocument xDoc = new XmlDocument();
        xDoc.PreserveWhitespace = preserveWhiteSpace;
        xDoc.LoadXml(xmlString);
        XmlNodeList list = xDoc.SelectNodes("//comment()");

        foreach (XmlNode node in list)
        {
            node.ParentNode.RemoveChild(node);
        }

        string xml;
        using (StringWriter sw = new StringWriter())
        {
            using (XmlTextWriter xtw = new XmlTextWriter(sw))
            {
                if (indention > 0)
                {
                    xtw.IndentChar = ' ';
                    xtw.Indentation = indention;
                    xtw.Formatting = System.Xml.Formatting.Indented;
                }

                xDoc.WriteContentTo(xtw);
                xtw.Close();
                sw.Close();
            }
            xml = sw.ToString();
        }

        return xml;
    }
+2

, , .

web.config:

<system.webServer>
    <rewrite>
        <rules>
            <clear />
            <!-- See transforming configs to see values inserted for builds -->
        </rules>
    </rewrite>

web.release.config transfrom ( ):

<system.webServer>
<rewrite >
  <rules xdt:Transform="Replace">
    <clear/>
    <rule name="Redirect to https" stopProcessing="true" >
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
    </rule>
  </rules>
</rewrite>

:

<system.webServer>
<rewrite>
  <rules>
    <clear />
    <rule name="Redirect to https" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
    </rule>
  </rules>
</rewrite>

LOT , , ...

In my case, I do not want to rewrite the rules in my database, but I added a comment to tell other developers to look in the transformations for more information, but I do not want this comment in the final version.

+1
source

All Articles