none
problem with quotes RRS feed

  • Question

  •  

    Hi

    I try to create a build task to do this transform in my web.config file:

        <httpModules>
         <!-- <remove name="UrlRewriterRoot" />-->


    To

        <httpModules>
         <remove name="UrlRewriterRoot" />


    So I added this:

    <XmlUpdate Namespace="http://schemas.microsoft.com/.NetConfiguration/v2.0"
          XmlFileName="$(ProjectRootIIS)\$(ProjectRootFOProd)\Web.config"
          Xpath="//comment()[.='<!-- <remove name="UrlRewriterRoot" /> -->')]"
          Value='<remove name="UrlRewriterRoot" />' />


    But I meet some problem I can't solve.

    XPath attribute: I should nest tree level of " and ', but I can't find a way for doing something like \" ou "" to protect the quote.
    the first < met seems to be problematic for msbuild because it interprets it as an opening markup. But this is the content of a string.
    this time again \< dos not work.


    Can anybody help me for writing this task?

    thank you


    Thank you!
    Wednesday, November 5, 2008 9:16 AM

Answers

  • Your replacement text is wrong.

    You have

    Replacement="&lt;remove name=&quot;remove name=&quot;UrlRewriterRoot&quot;/&gt;" rather than
    Replacement="&lt;remove name=&quot;UrlRewriterRoot&quot; /&gt;"

    so your config file is being corrupted.

    Mike
    • Marked as answer by Frédo Thursday, November 6, 2008 1:26 PM
    Thursday, November 6, 2008 11:01 AM
    Moderator

All replies

  • You may be better off using a 'replace' task.

    You could probably tweak the input regex, but this works for me.

        <Target Name="Default">
            <ItemGroup>
                <FilesToParse Include="C:\Demo1\config.txt"/>
            </ItemGroup>
            <MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace" RegexPattern="&lt;!-- &lt;remove name=&quot;UrlRewriterRoot&quot; /&gt;--&gt;" Replacement="&lt;remove name=&quot;UrlRewriterRoot&quot; /&gt;" Files="@(FilesToParse)"/>    
        </Target>

    If you are not on .net 3.5 and cant use the MSBuild Extension Pack, then I think the SDC Tasks has a similar task.

    Mike
    Wednesday, November 5, 2008 10:09 AM
    Moderator
  • Thanks for the answer

    I tried, but I got this error message:

     error : 'UrlRewriterRoot' is an unexpected token. Expecting white space. Line 132, position 33.
    Done building target "UpdateConfig" in project "MsBuild_frontofficeProd.proj" -- FAILED.


    'UrlRewriterRoot is not a token, this is my regex pattern!!!!

    any idea?


    Thank you!
    Thursday, November 6, 2008 9:08 AM
  • Can you post your sample.
    Thursday, November 6, 2008 9:22 AM
    Moderator
  • yes:

        <MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace" RegexPattern="&lt;!-- &lt;remove name=&quot;UrlRewriterRoot&quot; /&gt;--&gt;" Replacement="&lt;remove name=&quot;remove name=&quot;UrlRewriterRoot&quot;/&gt;" Files="$(ProjectRootIIS)\$(ProjectRootFOProd)\Web.config"></MSBuild.ExtensionPack.FileSystem.File>

    Thank you!
    Thursday, November 6, 2008 10:33 AM
  • Your replacement text is wrong.

    You have

    Replacement="&lt;remove name=&quot;remove name=&quot;UrlRewriterRoot&quot;/&gt;" rather than
    Replacement="&lt;remove name=&quot;UrlRewriterRoot&quot; /&gt;"

    so your config file is being corrupted.

    Mike
    • Marked as answer by Frédo Thursday, November 6, 2008 1:26 PM
    Thursday, November 6, 2008 11:01 AM
    Moderator
  • thank, it's working

    don't understand why I did not see this!
    Thank you!
    Thursday, November 6, 2008 1:27 PM