Exemple #1
0
        public Task <IPluginDependencyContext> FromPluginLoadContext(IPluginLoadContext pluginLoadContext)
        {
            var hostDependencies   = new List <HostDependency>();
            var remoteDependencies = new List <RemoteDependency>();

            // var runtimePlatformContext = pluginLoadContext.RuntimePlatformContext.ThrowIfNull(nameof(pluginLoadContext.RuntimePlatformContext));

            foreach (var type in pluginLoadContext.HostTypes)
            {
                // Load host types from current app domain
                LoadAssemblyAndReferencesFromCurrentAppDomain(type.Assembly.GetName(), hostDependencies, pluginLoadContext.DowngradableHostTypes, pluginLoadContext.DowngradableHostAssemblies);
            }

            foreach (var assemblyFileName in pluginLoadContext.HostAssemblies)
            {
                // Load host types from current app domain
                LoadAssemblyAndReferencesFromCurrentAppDomain(assemblyFileName, hostDependencies, pluginLoadContext.DowngradableHostTypes, pluginLoadContext.DowngradableHostAssemblies);
            }

            foreach (var type in pluginLoadContext.RemoteTypes)
            {
                remoteDependencies.Add(new RemoteDependency
                {
                    DependencyName = type.Assembly.GetName()
                });
            }

            var dependencyContext = GetDependencyContext(pluginLoadContext.FullPathToPluginAssembly);
            var pluginFramework   = dependencyContext.Target.Framework;

            CheckFrameworkCompatibility(pluginLoadContext.HostFramework, pluginFramework, pluginLoadContext.IgnorePlatformInconsistencies);

            var pluginDependencies   = GetPluginDependencies(dependencyContext);
            var resourceDependencies = GetResourceDependencies(dependencyContext);
            var platformDependencies = GetPlatformDependencies(dependencyContext, this.runtimePlatformContext.GetPlatformExtensions());

            var pluginDependencyContext = new DefaultPluginDependencyContext(
                pluginLoadContext.FullPathToPluginAssembly,
                hostDependencies,
                remoteDependencies,
                pluginDependencies,
                resourceDependencies,
                platformDependencies,
                pluginLoadContext.AdditionalProbingPaths
                );

            Validate(pluginDependencyContext);

            return(Task.FromResult <IPluginDependencyContext>(pluginDependencyContext));
        }
Exemple #2
0
        private static void Validate(DefaultPluginDependencyContext dependencyContext)
        {
            var hostDependenciesThatExistInPlugin = dependencyContext.HostDependencies
                                                    .Join(dependencyContext.PluginDependencies, h => h.DependencyName.Name, p => p.DependencyNameWithoutExtension, (h, p) => new
            {
                Host   = h,
                Plugin = p
            });

            foreach (var duplicateDependency in hostDependenciesThatExistInPlugin)
            {
                Debug.WriteLine($"Plugin dependency {duplicateDependency.Plugin.DependencyNameWithoutExtension} {duplicateDependency.Plugin.SemVer} exists in the host");
                if (duplicateDependency.Host.SemVer > duplicateDependency.Plugin.SemVer)
                {
                    Debug.WriteLine($"Host dependency {duplicateDependency.Host.DependencyName.Name} version {duplicateDependency.Host.SemVer} is newer than the Plugin {duplicateDependency.Plugin.SemVer}");
                }
                if (duplicateDependency.Host.SemVer < duplicateDependency.Plugin.SemVer)
                {
                    Debug.WriteLine($"Plugin dependency {duplicateDependency.Plugin.DependencyNameWithoutExtension} version {duplicateDependency.Plugin.SemVer} is newer than the Host {duplicateDependency.Host.SemVer}");
                }
            }
        }