Wix XmlFile 删除 mex 端点行
Wix XmlFile delete mex endpoint line
我目前正在编写一个 WiX 安装程序,生成的软件在 .exe.config 中留下了 mex 端点行,这在 development/debug 系统上没问题,但对于生产它需要被移除。
到目前为止,我没有成功尝试使用多种方法(首先使用 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 部分,因为如果可以避免的话,我不想硬依赖安装程序中的端点地址。
如前所述,我真的不知道下一步该尝试什么,因为我认为我已经用尽了所有选项并且没有 Whosebug post 似乎有效:
- 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
EDIT/UPDATE:
评论中提到的我试过的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" 在复制文件之前运行,而不是之后运行。 return 值为 1.. 根本没有错误记录。
所以它似乎已经自行解决,主要问题似乎是 verifypath 和 elementpath 属性,所以正如 @RitMo2k 在评论中建议的那样,我改为查看绑定类型,而不是地址。这似乎已经解决了它,代码如下所示,希望它能在将来帮助某人。
<Component Id="RemoveMexEndpoint" Directory="InstallFolder" Guid="*" KeyPath="yes">
<util:XmlConfig Id="RemoveMexEndpoint"
On="install"
Action="delete"
File="[#MyExeConfig]"
Node="element"
VerifyPath="//configuration/system.serviceModel/services/service[\[]@behaviorConfiguration='MainServiceBehaviour'[\]]/endpoint[\[]@binding='mexTcpBinding'[\]]"
ElementPath="//configuration/system.serviceModel/services/service[\[]@behaviorConfiguration='MainServiceBehaviour'[\]]"
PreserveModifiedDate="yes" />
</Component>
我目前正在编写一个 WiX 安装程序,生成的软件在 .exe.config 中留下了 mex 端点行,这在 development/debug 系统上没问题,但对于生产它需要被移除。
到目前为止,我没有成功尝试使用多种方法(首先使用 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 部分,因为如果可以避免的话,我不想硬依赖安装程序中的端点地址。
如前所述,我真的不知道下一步该尝试什么,因为我认为我已经用尽了所有选项并且没有 Whosebug post 似乎有效:
- 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
EDIT/UPDATE:
评论中提到的我试过的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" 在复制文件之前运行,而不是之后运行。 return 值为 1.. 根本没有错误记录。
所以它似乎已经自行解决,主要问题似乎是 verifypath 和 elementpath 属性,所以正如 @RitMo2k 在评论中建议的那样,我改为查看绑定类型,而不是地址。这似乎已经解决了它,代码如下所示,希望它能在将来帮助某人。
<Component Id="RemoveMexEndpoint" Directory="InstallFolder" Guid="*" KeyPath="yes">
<util:XmlConfig Id="RemoveMexEndpoint"
On="install"
Action="delete"
File="[#MyExeConfig]"
Node="element"
VerifyPath="//configuration/system.serviceModel/services/service[\[]@behaviorConfiguration='MainServiceBehaviour'[\]]/endpoint[\[]@binding='mexTcpBinding'[\]]"
ElementPath="//configuration/system.serviceModel/services/service[\[]@behaviorConfiguration='MainServiceBehaviour'[\]]"
PreserveModifiedDate="yes" />
</Component>