2010-06-02 53 views

回答

3

我找到了答案。看来这是Visual Studio/Team Build中XDT转换引擎中的一个已知错误。这个bug在3月份有报道,所以不知道什么时候会修复。

Here's the link

编辑:此链接实际上是不相关的原题。我们最终认为,内置的web配置转换是不可能的。所以我们最终编写了一个控制台应用程序去除注释,并正确格式化转换后的文件。

+0

该错误似乎与删除评论没有任何关系。 – 2011-09-08 14:15:22

+0

可以按照http://sedodream.com/2010/09/09/ExtendingXMLWebconfigConfigTransformation.aspx中所述扩展转换。也许,它也可以用于删除评论。 – 2012-08-04 00:44:17

2

这是我的功能。您可以将它添加到帮助程序类中:

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; 
    } 
1

如果您有小型部分要删除注释,您可能愿意使用替换转换。

基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> 

使用这种方法,你最终可能会将大量配置从基础复制到转换文件,但它可能是ap在小案例propriate ...

在我的情况下,我不想在我的基地重写规则,但我把一个评论告诉其他开发人员在变换中寻找更多的信息,但我不想在最后的评论版。

相关问题