open Microsoft.FSharp.Reflection
let RedirectAssembly shortName (targetVersion : Version) publicKeyToken =
let rec onResolveEvent = new ResolveEventHandler( fun sender evArgs ->
AssemblyName(evArgs.Name)
if requestedAssembly.Name <> shortName
Unchecked.defaultof<Assembly>
"Redirecting assembly load of %s ,\tloaded by %s"
(if evArgs.RequestingAssembly = null then
evArgs.RequestingAssembly.FullName)
requestedAssembly.Version <- targetVersion
requestedAssembly.SetPublicKeyToken (AssemblyName(sprintf "x, PublicKeyToken=%s" publicKeyToken).GetPublicKeyToken())
requestedAssembly.CultureInfo <- System.Globalization.CultureInfo.InvariantCulture
AppDomain.CurrentDomain.remove_AssemblyResolve(onResolveEvent)
Assembly.Load (requestedAssembly)
AppDomain.CurrentDomain.add_AssemblyResolve(onResolveEvent)