Exemple #1
0
        internal static string[] GetReferencingPlayerAssembliesForDLL(string dllPath, string assembliesOutputPath)
        {
            DefaultAssemblyResolver resolverRoot = new DefaultAssemblyResolver();

            resolverRoot.AddSearchDirectory(Path.GetDirectoryName(dllPath));
            AssemblyDefinition assemblyRoot = AssemblyDefinition.ReadAssembly(dllPath, new ReaderParameters {
                AssemblyResolver = resolverRoot
            });

            string[]      assemblyPaths         = BuildPipeline.GetManagedPlayerDllPaths(assembliesOutputPath);
            List <string> referencingAssemblies = new List <string>();

            // determine whether there is an assembly that is referencing the assembly path
            foreach (string assemblyPath in assemblyPaths)
            {
                DefaultAssemblyResolver resolver = new DefaultAssemblyResolver();
                resolver.AddSearchDirectory(Path.GetDirectoryName(assemblyPath));
                AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(assemblyPath, new ReaderParameters {
                    AssemblyResolver = resolver
                });

                foreach (AssemblyNameReference anr in assembly.MainModule.AssemblyReferences)
                {
                    if (anr.FullName == assemblyRoot.Name.FullName)
                    {
                        referencingAssemblies.Add(assemblyPath);
                    }
                }
            }

            return(referencingAssemblies.ToArray());
        }
        internal static string[] GetReferencingPlayerAssembliesForDLL(string dllPath)
        {
            DefaultAssemblyResolver defaultAssemblyResolver = new DefaultAssemblyResolver();

            defaultAssemblyResolver.AddSearchDirectory(Path.GetDirectoryName(dllPath));
            AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(dllPath, new ReaderParameters
            {
                AssemblyResolver = defaultAssemblyResolver
            });

            string[]      managedPlayerDllPaths = BuildPipeline.GetManagedPlayerDllPaths();
            List <string> list = new List <string>();

            string[] array = managedPlayerDllPaths;
            for (int i = 0; i < array.Length; i++)
            {
                string text = array[i];
                DefaultAssemblyResolver defaultAssemblyResolver2 = new DefaultAssemblyResolver();
                defaultAssemblyResolver2.AddSearchDirectory(Path.GetDirectoryName(text));
                AssemblyDefinition assemblyDefinition2 = AssemblyDefinition.ReadAssembly(text, new ReaderParameters
                {
                    AssemblyResolver = defaultAssemblyResolver2
                });
                foreach (AssemblyNameReference current in assemblyDefinition2.MainModule.AssemblyReferences)
                {
                    if (current.FullName == assemblyDefinition.Name.FullName)
                    {
                        list.Add(text);
                    }
                }
            }
            return(list.ToArray());
        }