【发布时间】:2018-06-18 15:40:31
【问题描述】:
我目前正在编写一个 WiX 安装程序,并且生成的软件在 .exe.config 中保留了 mex 端点行,这在开发/调试系统上很好,但对于生产它需要被删除。
到目前为止,我在尝试使用多种方法(首先使用util:XmlConfig,现在使用util:XmlFile)从 .exe.config 中删除此条目方面没有成功,希望这里有人会使用它并有更多经验,因为我现在在这方面花了太长时间(尴尬的是将近 2 天..)。
XML .exe.config(已编辑):
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="MainServiceBehaviour"
name="MyService">
<endpoint address="net.tcp://localhost:1111/endpoint" binding="netTcpBinding"
bindingConfiguration="netTcp" contract="project.ServiceInterface"/>
<endpoint address="net.tcp://localhost:1111/endpoint/mex"
binding="mexTcpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:1111/endpoint"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
试图删除第二个端点的 WiX 部分:
<Component Id="RemoveMexEndpoint" Directory="" Guid="*" KeyPath="yes">
<util:XmlFile Id="RemoveMexEndpointEntry"
Action="deleteValue"
Name="endpoint"
ElementPath="//configuration/system.serviceModel/services/service[\[]@behaviorConfiguration='MainServiceBehaviour'[\]]/endpoint[\[]@address='net.tcp://localhost:1111/endpoint/mex'[\]]"
File="[#MyExeConfig]"
PreserveModifiedDate="yes"
SelectionLanguage="XPath" />
</Component>
我最初尝试使用 endpoint[\[]contains(@address,"mex")[\]] 的 WiX 部分,因为如果可以避免的话,我不想硬依赖安装程序中的端点地址。
如前所述,我真的不知道下一步该尝试什么,因为我认为我已经用尽了所有选项,而且似乎没有 StackOverflow 帖子有效:
- Deleting XML element with XmlConfig extension in WIX using XPath
- https://blogs.technet.microsoft.com/alexshev/2009/05/27/from-msi-to-wix-part-25-installable-items-updating-xml-files-using-xmlfile/
- Deleting XML elements in WiX
编辑/更新:
我在 cmets 中尝试过的 XmlConfig
<util:XmlConfig Id="RemoveMexEndpoint"
On="install"
Action="delete"
File="[#MyExeConfig]"
Node="element"
VerifyPath="//configuration/system.serviceModel/services/service[\[]@behaviorConfiguration='MainServiceBehaviour'[\]]/endpoint[\[]@address='net.tcp://localhost:8111/endpoint/mex'[\]]"
ElementPath="//configuration/system.serviceModel/services/service[\[]@behaviorConfiguration='MainServiceBehaviour'[\]]"
PreserveModifiedDate="yes" />
我能在日志中看到的是“ExecXmlConfig”在文件被复制之前运行,而不是之后。并且返回值为 1.. 根本没有记录错误。
【问题讨论】:
-
正如您引用的第一个问题所示,
XMLFile扩展无法删除元素,请将XMLConfig与@Action="delete"一起使用。另外,为什么不在 XPATH 表达式中过滤@binding="mexTcpBinding"上的元素? -
我尝试了
xmlconfig,但也没有用。以为我把这个问题放在了对不起。明天回来工作时将使用该代码摘录进行更新。好地方,我专注于地址部分。我明天会用调查结果更新问题,不幸的是我现在没有笔记本电脑可以尝试。
标签: xml wix app-config