Adding dynamic redirects. Fix for #793

Fix for #793 

*Do not merge this yet!!!!*

This change removes all static binding redirects in app.config, and introduces dynamic redirects in core. The way this is done is by listening to the AssemblyResolve event on the AppDomain, and loading / returning the assembly to redirect to. It turns out using this technique you can swap on the fly and give a different assembly than what was requested.

At startup, it builds a map in map in memory based on the assemblies that scriptcs ships with ensuring that any requests for the same names will be redirected to it's version. It also ensures that any packages in the scriptcs packages folder take precedence over what the script pack / packages assemblies were actually compiled against.

Assembly black magic at its finest....

It appears to work so far :-)

This does not fix the Service Stack script pack issue, as there appears to be no magical fix for that other than updating the script pack. However, I was able to get the old Web Api script pack to work with the latest Web Api (see comments)


Ok, well the builder created the resolver so adding code to call its
dispose is not a big deal.

On Monday, July 14, 2014, Adam Ralph <notifications@github.com> wrote:

> In src/ScriptCs.Core/AppDomainAssemblyResolver.cs:
>
> > +using System.Linq;
> > +using System.Reflection;
> > +using System.Text;
> > +using System.Threading.Tasks;
> > +
> > +namespace ScriptCs
> > +{
> > +    public class AppDomainAssemblyResolver
> > +    {
> > +        private readonly ILog _logger;
> > +        private IDictionary<string, AssemblyInfo> _assemblyInfoMap = new Dictionary<string, AssemblyInfo>();
> > +
> > +        public AppDomainAssemblyResolver(ILog logger)
> > +        {
> > +            _logger = logger;
> > +            AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
>
> Bear in mind that you are then buying into a chain of IDisposable
> implementations. If you follow the call stack upwards you'll find that
> ScriptServicesBuilder and ICommand would have implement IDisposable too
> and the implementation of WatchCommand and ExecuteScriptCommand will have
> to change to be passed the builder and keep a reference to it so that they
> can dispose it.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/scriptcs/scriptcs/pull/798/files#r14918817>.
>