1

I am working on a web application. the Web.config file is set to NeverOverwrite (=yes) in its initial installation. Now i need to add DBproviderfactories like below. Can i add this entire block using XmlFile in a patch.msp? I do not want to write a custom action. All I need is to add this block in the web.config. Any suggestion here is appreciated.

<system.data>
<DbProviderFactories>
  <!-- Remove in case this is already defined in machine.config -->      
  <remove invariant="Oracle.ManagedDataAccess.Client" />
  <add name="Oracle Data Provider for .NET" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
MPK
  • 77
  • 1
  • 7
  • I haven't tried, [maybe check this](https://stackoverflow.com/a/49162863/129130). – Stein Åsmul Jan 20 '20 at 14:50
  • Is the Web.config file set to "permanent" in the first version? If not, you will potentially get issues with the file being uninstalled and reinstall during major upgrade scenarios. – Stein Åsmul Jan 20 '20 at 19:33

1 Answers1

0

Sample: Maybe try this: https://github.com/glytzhkof/WiXUpdateXmlFile

  • Below is the gist of it - please use the sample above for testing. The markup below is just for illustration.

  • Set the XML file both permanent and never overwrite.

  • See inline instructions in the sample above for testing.

  • Check what happens on uninstall - this markup will remove the entries it added.

        <!-- Set app.config permanent and never overwrite to yes -->
        <Component Feature="ProductFeature" NeverOverwrite="yes" Permanent="yes">
          <File Source="app.config" />
        </Component>
    
        <!-- The XML update -->
    
        <!-- Use a NEW GUID here, do not go live with this one -->
        <Component Id="XmlFileUpdate" Guid="{00000000-0000-0000-0000-7405EED51B57}" Feature='ProductFeature'>
    
          <!--Create New Element-->
          <util:XmlFile Id='XmlSettings1' File='[INSTALLFOLDER]app.config' Action='createElement' Name='MyConfig' ElementPath='//configuration' Sequence='1' />
    
          <!--Set New Value-->
          <util:XmlFile Id='XmlSettings2' File='[INSTALLFOLDER]app.config' Action='setValue' Name='newVersion' Value='6.6.8' ElementPath='//configuration/MyConfig' Sequence='2' />
    
          <!--Set New Value-->
          <util:XmlFile Id='XmlSettings3' File='[INSTALLFOLDER]app.config' Action='setValue' Name='Server' Value='Pusevov' ElementPath='//configuration/MyConfig' Sequence='3' />
    
          <!--Update Existing Value, Existing Element-->
          <util:XmlFile Id='XmlSettings4' File='[INSTALLFOLDER]app.config'
            Action='setValue' Name='newVersion' Value='7.7.7' ElementPath='//configuration/ExistingConfig/bindingRedirect' Sequence='4' />
    
          <CreateFolder />
        </Component>
    
      </Directory>
    </Directory>
    

Link:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164