public void BaseTest(string name)
        {
            var json  = ResourcesUtilities.ReadFileAsString(name);
            var paths = DepsJsonDependenciesSearcher.Search(json);

            Console.WriteLine("Dependencies:");
            foreach (var path in paths)
            {
                Console.WriteLine($" - {path}");
            }

            Assert.IsNotNull(paths);
            Assert.IsTrue(paths.Any(), "paths.Any()");
        }
예제 #2
0
        public static IList <string> GetDllPaths(this Assembly assembly, int level = 0)
        {
            var list = new List <string> {
                assembly.Location
            };

            var depsJsonPath = $"{assembly.Location.Substring(0, assembly.Location.Length - 4)}.deps.json";

            if (File.Exists(depsJsonPath))
            {
                var json = File.ReadAllText(depsJsonPath);

                return(DepsJsonDependenciesSearcher.Search(json));
            }

            var folder        = assembly.GetFolder();
            var assemblyNames = assembly.GetReferencedAssemblies();
            var references    = assemblyNames
                                .Select(assemblyName => assemblyName.CodeBase?.Replace(@"file:///", string.Empty) ?? Path.Combine(folder, assemblyName.Name + ".dll"))
                                .Where(i => !Path.GetFileName(i).StartsWith("System.") &&
                                       !Path.GetFileName(i).StartsWith("mscorlib") &&
                                       !Path.GetFileName(i).StartsWith("netstandard"))
                                .Where(File.Exists)
                                .ToArray();

            list.AddRange(references);
            list.AddRange(references
                          .Select(Assembly.LoadFrom)
                          .SelectMany(i => GetDllPaths(i, level + 1)));

            // TODO: rough fix
            if (level == 0)
            {
                // Emgu.CV and other wrapper fix
                list.AddRange(GetFilesIfExists(Path.Combine(folder, "x86")));
                list.AddRange(GetFilesIfExists(Path.Combine(folder, "x64")));
            }

            list = list.Distinct(StringComparer.OrdinalIgnoreCase).ToList();

            return(list);
        }