private static Factory.Collection _LoadPluginsFunc(ProjectDOM.Project project, PathString prjDir)
        {
            LoadProjectAssemblies(project, prjDir);

            if (true) // load locally referenced assemblies
            {
                var entry = AssemblyServices.GetEntryAssembly();

                if (entry != null)
                {
                    var arefs = entry.GetReferencedAssemblies();
                    foreach (var aname in arefs)
                    {
                        if (string.IsNullOrWhiteSpace(aname.CodeBase))
                        {
                            continue;
                        }

                        PluginLoader.Instance.UsePlugin(new PathString(aname.CodeBase));
                    }
                }
            }


            return(PluginLoader.Instance.GetPlugins().GetContentInfoCollection());
        }
Example #2
0
        private Assembly _AssemblyResolve(AssemblyName aname)
        {
            // https://msdn.microsoft.com/en-us/library/ff527268.aspx

            // this can be called by any thread

            string dllName = aname.Name + ".dll";

            PathString[] probeDirs = null;

            lock (_Lock)
            {
                _ResolvedAssemblies[dllName] = PathString.Empty;
                probeDirs = _ProbeDirectories.ToArray();
            }

            foreach (var probeDir in probeDirs)
            {
                var fullPath = System.IO.Path.Combine(probeDir, dllName);

                if (!System.IO.File.Exists(fullPath))
                {
                    continue;
                }

                try
                {
                    var a = AssemblyServices.LoadAssemblyFromFilePath(fullPath);
                    if (a != null)
                    {
                        System.Diagnostics.Debug.WriteLine("LOADED ASSEMBLY: " + fullPath);

                        lock (_Lock) { _ResolvedAssemblies[aname.Name] = new PathString(fullPath); }
                        return(a);
                    }
                }
                catch { }
            }

            System.Diagnostics.Debug.WriteLine("FAILED LOADING ASSEMBLY: " + dllName);

            return(null);
        }
Example #3
0
        public void UsePlugin(PathString pluginAbsPath)
        {
            // TODO: if an assembly exists in the path, read the AssemblyName and check if we already have it in our plugins dir.

            if (!pluginAbsPath.CheckPluginCompatibility())
            {
                return;
            }

            // store assembly directory path, so we can recursively resolve dependencies when the assembly is loaded.
            lock (_Lock)
            {
                _ProbeDirectories.Add(pluginAbsPath.DirectoryPath);
            }

            try
            {
                var a = AssemblyServices.LoadAssemblyFromFilePath(pluginAbsPath);

                if (a == null)
                {
                    return;
                }

                a.DefinedTypes.ToArray(); // if not compatible, this throws ReflectionTypeLoadException

                _Plugins.Add(a);
            }
            catch (Exception ex)
            {
                // Net.Standard projects by default don't copy assemblies to the BIN folder.
                // To Copy assemblies locally, add this property to the project; <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
                // https://github.com/dotnet/sdk/issues/933

                // https://github.com/dotnet/sdk/issues/598
                // https://github.com/dotnet/sdk/issues/747
            }
        }
Example #4
0
 private _PluginsFactoryWithResolver()
 {
     AssemblyServices.SetDefaultAssemblyResolver(_AssemblyResolve);
 }