【问题标题】:problems with xmlpoke in nant script when reading a semicolon in a string读取字符串中的分号时,nant 脚本中的 xmlpoke 出现问题
【发布时间】:2026-01-27 00:20:02
【问题描述】:

我有一个 nant 脚本试图更改我的 web.config 中的 URL 值,但 Nant 不断抛出此错误:

'=' is an unexpected token. The expected token is ';'. Line 1, position 80.

我将其追溯到 nant 脚本 URL 中的分号。我首先在 URL 中使用分号的原因是 web.config 不喜欢与符号 (&)。所以我不得不用&替换&。这是我的 web.config 值:

<appSettings>
    <add key="myUrl" value="http://www.google.com/whatever?id=myId&amp;fullScreen=1"/>
</appSettings>

我可以在 web.config 中对所有其他“添加键”进行 xmlpoke,但这个不是 xpath 问题。 这是 nant 脚本:

<property name="myUrl" value="http://www.google.com/whatever?id=123456&amp;fullScreen=2"/>

<xmlpoke 
   file="${config.file}"
   xpath="/configuration/appSettings/add[@key = 'myUrl']/@value"
   value="${myUrl}">    
</xmlpoke>

所以问题不在于 web.config 中的分号,而在于 nant 脚本中的分号。我想我需要以某种方式转义 nant 脚本中的分号。任何人都知道如何执行此操作或其他方法以使其正常工作?

【问题讨论】:

    标签: asp.net ant web-config nant xmlpoke


    【解决方案1】:

    已经 16 个小时了,没人偷看。幸运的是,经过几个小时的谷歌搜索,我找到了解决方案。

    解决方案是使用&amp;amp;amp;。我不知道为什么额外的amp; 但它起作用了。 所以现在我的 nant 脚本看起来像这样:

    <property name="myUrl" value="http://www.google.com/whatever?id=123456&amp;amp;fullScreen=2"/>
    

    感谢 Gary from the nant-users mailing list,我刚刚订阅了 :)

    【讨论】: