Configuration Files

 

  1. This example assumes that you have worked on the AssemblyVersioning example.
  2. In this example we will see how we can modify the version of assembly that we use, without modifying the code or recompiling.
  3. Click on the start button, settings, control panel. Double click on Administrative tools. Double click on Microsoft .NET Framework Configuration.
  4. Click on Manage Individual Applications.
  5. Click on Add an Application to Configure.
  6. Either select the application from the list, or click on Other and navigate to the User.exe from AssemblyVersioning.
  7. Make sure in the tree view on the left, under Applications, User.exe is selected.
  8. Click on the View the Assembly Dependencies.
  9. The list of assemblies that this application depends on is shown.
  10. Now, in the tree view on the left, select Configured Assemblies:

  1. Click on Configure an Assembly.
  2. In the resulting dialog, choose the appropriate option as shown below:

  1. Click on Choose Assembly… button.
  2. Select the ASampleClass, and click on Select. Click on Finish.
  3. In the ASampleClass Properites dialog, click on Binding Policy tab.
  4. Now view the assembly directory (C:\Winnt\assembly) using Windows Explorer.
  5. Right click on the ASampleClass assembly, the older version and click on properties.
  6. In this dialog, highlight the version number (some thing like 1.0.859.31296) and click right mouse button and copy to clipboard.
  7. Back in the ASampleClass Properties in the .NET Configuration tool, paste that version number in Requested Version.
  8. Similarly, pick the version number of newer ASampleClass assembly and paste it into the New Version.
  9. Click on Apply and OK.
  10. Double click on the User.exe in Windows Explorer and see what the output is.
  11. Now go back to the dialog that allows you to set the version numbers and swap the version numbers and see what the output is.
  12. Finally, lets find the configuration file that was updated by this process.
  13. Go to the bin\Debug directory where the User.exe is located. Notice there is a new file named User.exe.config that has been created. Open that file in notepad and view.

<?xml version="1.0"?>

<configuration>

  <runtime>

    <assemblyBinding

       xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity

           name="ASampleClass"

           publicKeyToken="17645102c31e109c" />

        <bindingRedirect

           oldVersion="1.0.859.31240"

           newVersion="1.0.859.31296" />

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

</configuration>