Wix:如何删除XML文件中的注释

时间:2014-04-01 15:04:42

标签: wix

我的应用程序中有以下配置文件:

<configuration>
    <appSettings>
        <!--Setting for user name-->
        <add key="wcf:userName" value="wcfuser" />
        <!--Setting for password-->
        <add key="wcf:userPassword" value="abcdef" />

        <!--Setting for is cloud application-->
        <add key="IsCloudApplication" value="true" />
    </appSettings>
<configuration>

我想通过Wix XmlConfig在生产服务器上删除此注释。我尝试使用以下代码:

<util:XmlConfig Id="RemoveWcfComments" File="[INSTALLFOLDER]Web.config" Action="delete" ElementPath="configuration/appSettings" VerifyPath="&lt;!--Settings for user name--&gt;" Node="element" On="install"/>

,但这不起作用:不会发生异常,但注释仍保留在配置文件中。有任何想法吗? 提前谢谢。

2 个答案:

答案 0 :(得分:0)

我不确定,但你可以试试这个:

<util:XmlConfig 
    Id="RemoveWcfComments"
    File="[INSTALLFOLDER]Web.config"
    Action="delete"
    ElementPath="//configuration/appSettings"
    VerifyPath="//configuration/appSettings/comment()"
    Node="value"
    On="install"/>

As you can see ElementPathVerifyPathXPath - s,因此它们在您的代码中无效。我不确定Node="value"是否正确,您也可以尝试Node="element"

答案 1 :(得分:0)

使用Xpath,Comment()方法将选择AppSettings下的所有注释,如果你有多个注释但只想删除一个注释,那么请使用下面的xpath:

VerifyPath="//configuration/appSettings/comment()[.='Settings for user name and password']"

如果有多条评论,并且您想根据订单删除第一条评论,那么您也可以使用以下xpath:

VerifyPath="//configuration/appSettings/comment()[1]"