How to deploy binding redirects (in app.config) without overriding custom config values?

Viewed 147

When I publish an update of a windows service (using a custom installer), I want to include the app.config because the binding redirects are in it and may have changed. If I don't update the app.config with binding redirects there may occure runtime errors, right?

But if the app.config on the client computer has some custom configuration values, these will be lost when it is overridden by the installer.

Any advice on how to handle this situation? I assume that this may be a common problem but havn't found any advice yet. I'm thinking about using a custom config file for all configuration that may need custom values on the client computer. (But then I wonder what the app.config is for other than binding redirects, which seems not to be the original intention.)

Here is an example app.config (note the appSettings section that should not be overridden):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <appSettings>
    <add key="SomeKey" value="CustomValueForSpecificClient" />
  </appSettings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
0 Answers
Related