コード例 #1
0
ファイル: Program.cs プロジェクト: caybokotze/dotnet-utils
        // Define other methods and classes here
        static IEnumerable <string> ListFileDeps(
            Assembly asm,
            List <AssemblyDependencyInfo> deps,
            string root,
            int listLevel = 0)
        {
            var errors = new List <string>();
            var refs   = asm.GetReferencedAssemblies();

            foreach (var r in refs.OrderBy(r => r.Name))
            {
                if (deps.Any(d => d.FullName == r.FullName))
                {
                    continue;
                }

                var dep = new AssemblyDependencyInfo(r, true, listLevel);
                deps.Add(dep);
                try
                {
                    ListAsmDeps(r.FullName, deps, root, listLevel + 1);
                }
                catch (FileNotFoundException ex)
                {
                    errors.Add($"Unable to find dependency: {r.FullName} {ex.FileName}");
                    dep.Loaded = false;
                }
            }

            return(errors);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: caybokotze/dotnet-utils
        private static string CreateRebindMessage(
            bool noColor,
            bool isRebound,
            bool isMismatched,
            bool successfullyRebound,
            AssemblyDependencyInfo dep,
            string spacing)
        {
            var successfulRebindMessage = successfullyRebound
                ? $"* rebound to:   {dep.LoadedAssembly.Version}"
                : "";

            if (!string.IsNullOrWhiteSpace(successfulRebindMessage))
            {
                return(IndentAndColor(successfulRebindMessage, s => s.BrightBlue()));
            }

            if (isMismatched)
            {
                var invalidRebindMessage = isRebound
                    ? "* invalid assembly rebind"
                    : "* assembly rebind suggested";
                return(IndentAndColor(invalidRebindMessage, s => s.BrightMagenta()));
            }

            return("");

            string IndentAndColor(string str, Func <string, string> colorizer)
            {
                if (string.IsNullOrWhiteSpace(str))
                {
                    return(str);
                }

                if (!noColor)
                {
                    str = colorizer(str);
                }

                return($"\n{spacing} {str}");
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: caybokotze/dotnet-utils
        static void ListAsmDeps(
            string asmName,
            List <AssemblyDependencyInfo> deps,
            string root,
            int listLevel = 0)
        {
            var asm = TryLoadPath(asmName);

            if (asm == null)
            {
                var name  = new AssemblyName(asmName);
                var check = Path.Combine(root, name.Name + ".dll");
                if (!File.Exists(check))
                {
                    throw new FileNotFoundException(check);
                }

                asm = TryLoadPath(check);
                var loadedAsmName = asm?.FullName?.ToString();
                if (!(loadedAsmName is null) && loadedAsmName != asmName)
                {
                    var depMatch = deps.FirstOrDefault(d => d.FullName == asmName);
                    depMatch?.StoreLoadedAssemblyName(new AssemblyName(loadedAsmName));
                }
            }

            if (asm != null)
            {
                var localPath = new Uri(asm.Location).LocalPath;
                foreach (var dep in deps.Where(d => d.Name == asm.GetName().Name))
                {
                    dep.SetPathOnDisk(localPath);
                }
            }

            var refs = asm?.GetReferencedAssemblies() ?? new AssemblyName[0];

            foreach (var r in refs)
            {
                if (deps.Any(d => d.FullName == r.FullName))
                {
                    continue;
                }

                var dep = new AssemblyDependencyInfo(r, true, listLevel);
                deps.Add(dep);
                try
                {
                    var assemblyName   = new AssemblyName(r.FullName);
                    var asmToCheckFile = Path.Combine(root, assemblyName.Name + ".dll");
                    if (File.Exists(asmToCheckFile))
                    {
                        var asmToCheck = TryLoadPath(asmToCheckFile);
                        if (asmToCheck == null)
                        {
                            continue;
                        }

                        dep.SetPathOnDisk(asmToCheckFile);
                        ListFileDeps(asmToCheck, deps, root, listLevel + 1);
                    }
                    else
                    {
                        ListAsmDeps(r.FullName, deps, root, listLevel + 1);
                    }
                }
                catch (FileNotFoundException)
                {
                    dep.Loaded = false;
                }
            }
        }