0

I am currently writing a WiX installer, and the software that is generated leaves the mex endpoint line in the .exe.config, this is fine on development/debug systems, but for production it needs to be removed.

I have had no success so far in trying to remove this entry from the .exe.config using multiple methods (first using util:XmlConfig and now with util:XmlFile) hopefully someone here will have used this and have a bit more experience as I have spent too long on this now (embarassingly nearly 2 days..).

The XML .exe.config (redacted):

<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>

The WiX section trying to delete the second endpoint:

<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>

I originally was trying the WiX section with endpoint[\[]contains(@address,"mex")[\]] as I didnt want to have a hard dependency on the endpoint address in the installer if avoidable.

As mentioned, I do not really know what to try next as I think I have exhausted all options and no StackOverflow post seems to work:

  1. Deleting XML element with XmlConfig extension in WIX using XPath
  2. https://blogs.technet.microsoft.com/alexshev/2009/05/27/from-msi-to-wix-part-25-installable-items-updating-xml-files-using-xmlfile/
  3. Deleting XML elements in WiX

EDIT/UPDATE:

The XmlConfig that I tried as mentioned in comments

<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" />

All I am able to see in the logs is that the "ExecXmlConfig" runs before the files are copied, not after. And that the return value is 1.. no logging of errors at all.

Chris Watts
  • 822
  • 1
  • 9
  • 27
  • Just as the first question you reference indicates, `XMLFile` extension cannot remove elements, use `XMLConfig` with `@Action="delete"`. Also, why not filter the element on the `@binding="mexTcpBinding"` in your XPATH expression? – Ritmo2k Jan 09 '18 at 17:46
  • I tried the `xmlconfig` and it also didn't work. Thought I had put that in the question sorry. Will update with that code excerpt tomorrow when back at work. Good spot, I was fixated on the address portion. I will update the question tomorrow with findings, unfortunately not got laptop with me to try it now. – Chris Watts Jan 09 '18 at 21:23

1 Answers1

0

So It seems to have resolved itself, the primary issue seemed to be the verifypath and elementpath attributes so as @RitMo2k suggested in comments, I changed to look at the binding type, not the address. This seems to have resolved it, code shown below so it can hopefully help someone in the future.

<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>
Chris Watts
  • 822
  • 1
  • 9
  • 27