コード例 #1
0
        public static IEnumerable <string> GetReferencedAssembliesPath(this _Assembly assembly, string location, bool includeSystemAssemblies = false)
        {
            Log.Write("GetReferencedAssembliesPath Started - Parameters assembly: {0}, includeSystemAssemblies: {1}", assembly.ToString(), includeSystemAssemblies);
            List <string> retPaths = new List <string>();

            List <string> referencedAssemblies = assembly.GetReferencedAssemblies()
                                                 .Where(name => includeSystemAssemblies || !IsSystemAssembly(name.Name))
                                                 .Select(name => name.Name)
                                                 .ToList();

            if (!referencedAssemblies.Any())
            {
                return(retPaths);
            }
            Log.Write($"There are {referencedAssemblies.Count} referenced non system assemblies");

            Log.Write($"Current Assembly is at location {assembly.Location}");

            string currentAssemblyPath = string.Empty;

            try
            {
                currentAssemblyPath = FileSystem.Path.GetDirectoryName(location);
            }
            catch (Exception exception)
            {
                Log.Write(exception,
                          $"GetDirectoryName of assembly: {assembly.FullName} failed. Path is wrong {assembly.Location}");
            }


            if (string.IsNullOrEmpty(currentAssemblyPath))
            {
                return(Enumerable.Empty <string>());
            }

            Log.Write("currentAssemblyPath: {0}", currentAssemblyPath);

            referencedAssemblies
            .ForEach(s =>
            {
                Log.Write("Assembly {0} Located in {1} References Assembly {2} ", assembly.GetName().Name,
                          assembly.Location, s);
                retPaths.Add(FindPath(s, currentAssemblyPath));
            });

            return(retPaths.Where(s => !string.IsNullOrEmpty(s)));
        }