Deploying Versioned Components

To illustrate how applications can be configured to use shared components that either are the latest or are known to be compatible, you must install both 2.0 versions of Reverser.dll into the assembly cache — which you do with the Build.bat file that uses the Global Assembly Cache Tool (Gacutil.exe):

gacutil.exe /i Reverser.dll

After installing these Reverser assemblies, you can then examine the assembly cache by navigating to the \WindowsDirectory\Assembly directory, and using the cache viewer shell extension:

You are now ready to compile the VerClient executable file, for which you specify version 2.0.0.0 of the Reverser component:

csc /reference:Stringer\Stringer.dll; 
...  Reverser_v2.0.0.0\Reverser.dll VerClient.cs

As mentioned in (3) Path for Private Components and Binding Policy, locating and binding to assemblies at run time can be controlled using an application-configuration file. In particular, the BindingRedirect tag can be used to redirect the reference to a different version of a strong-named assembly, by overriding the version in the original reference with this newer version. The following option says that for any assembly reference from version 2.0.0.0 through 2.0.0.9, the version that should instead be used at run time is 2.0.1.0:

<bindingRedirect
   oldVersion="2.0.0.0-2.0.0.9" newVersion="2.0.1.0"
/>

This allows an administrator to reconfigure an application without having to have it recompiled.

The sample VerClient.exe.config file in the 5_Versioned subdirectory demonstrates this option.

Listing 2. Configuration File for VerClient.exe (VerClient.exe.config)

<configuration>   
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="Stringer"/>
      <publisherPolicy apply="no"/>
      <dependentAssembly>
        <assemblyIdentity name="Reverser" 
            publicKeyToken="0038acc8beadf1e5"
            culture=""/>
        <publisherPolicy apply="no"/>
        <bindingRedirect oldVersion="2.0.0.0"
          newVersion="2.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>  

Since a method of a type in version 2.0.1.0 of Reverser.dll was deliberately made incompatible with the same method in version 2.0.0.0, a version 2.0.0.0–compatible client that attempts to call this later revision will fail. By changing from:

    newVersion="2.0.0.0"

to:

    newVersion="2.0.1.0"

It is possible for you to demonstrate this behavior, which results in a MissingMethodException. More typically, this mechanism allows an administrator to repair an application so that it will continue to run successfully if it happens to be broken by a subsequent install of another application that used a different version of the same shared component.

Finally, when it comes time to clean up the application, you should remove the shared component files from the assembly cache:

gacutil /u reverser

This mechanism removes all versions of a component from the assembly cache. If the component is still located in the application's private path or in a subdirectory that equals the component's name, it will subsequently be loaded from that location.

See Also

Packaging and Deployment Summary | Appendix A: Additional Packaging and Deployment Information | Appendix B: Packaging and Deployment Tools