2010-06-02 54 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 ...

在我的情況下,我不想在我的基地重寫規則,但我把一個評論告訴其他開發人員在變換中尋找更多的信息,但我不想在最後的評論版。

相關問題