Exemple #1
0
        /// <summary>
        /// 获取依赖的程序集名称,该方法采用Assembly.LoadFile(string path)方法,该方法虽然没有解决dll文件被占用和资源释放的问题,但是通过拷贝文件到临时目录,间接地解决了内存不断极速增加的问题。
        /// </summary>
        /// <param name="dllPath">dll路径</param>
        /// <returns></returns>
        public static List <string> GetRefDlls(string dllPath)
        {
            List <string> rlts = new List <string>();

            try
            {
                string tempDllDir = Path.Combine(TempDir, SubDirGuid);
                if (Directory.Exists(tempDllDir) == false)
                {
                    Directory.CreateDirectory(tempDllDir);
                }
                string tempDllPath = Path.Combine(tempDllDir, Path.GetFileName(dllPath));
                if (File.Exists(tempDllPath) == false)
                {
                    File.Copy(dllPath, tempDllPath);
                }
                Assembly       ass    = Assembly.LoadFile(tempDllPath);
                AssemblyName[] refAss = ass.GetReferencedAssemblies();
                if (refAss != null)
                {
                    for (int i = 0; i < refAss.Length; i++)
                    {
                        string dllName = refAss[i].Name;
                        rlts.Add(dllName);
                    }
                }
            }
            catch (Exception ex)
            {
                LogoUtility.Log("Leation.VSAddin.GetRefDlls", ex.Message);
            }
            return(rlts);
        }
Exemple #2
0
        /// <summary>
        /// 获取依赖的程序集名称,,该方法采用Assembly.Load(byte[] rawAssembly)方法,该方法解决了dll文件被占用的问题,但是依然没有释放资源,会导致visual studio内存极速增加,直到接近100%
        /// </summary>
        /// <param name="dllPath">dll路径</param>
        /// <returns></returns>
        public static List <string> GetRefDllsPlus(string dllPath)
        {
            List <string> rlts = new List <string>();

            try
            {
                byte[]         bs     = File.ReadAllBytes(dllPath);
                Assembly       ass    = Assembly.Load(bs);
                AssemblyName[] refAss = ass.GetReferencedAssemblies();
                if (refAss != null)
                {
                    for (int i = 0; i < refAss.Length; i++)
                    {
                        string dllName = refAss[i].Name;
                        rlts.Add(dllName);
                    }
                }
                bs     = null;
                refAss = null;
                ass    = null;
            }
            catch (Exception ex)
            {
                LogoUtility.Log("Leation.VSAddin.GetRefDllsPlus", ex.Message);
            }
            return(rlts);
        }