|
@@ -9,12 +9,12 @@ public static class AppDomainExtents
|
|
/// <param name="prefix">程序集前缀</param>
|
|
/// <param name="prefix">程序集前缀</param>
|
|
/// <remarks>如果某个dll被反射加载,同时程序被发布为自包含的单个exe程序,这种dll目前检测不到</remarks>
|
|
/// <remarks>如果某个dll被反射加载,同时程序被发布为自包含的单个exe程序,这种dll目前检测不到</remarks>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- public static Assembly[] GetAllAssemblies(this AppDomain domain, string prefix = "DW5S")
|
|
|
|
|
|
+ public static Assembly[] GetAllAssemblies(this AppDomain domain, string dllKey = "DW5S")
|
|
{
|
|
{
|
|
Dictionary<string, Assembly> dic = new Dictionary<string, Assembly>();
|
|
Dictionary<string, Assembly> dic = new Dictionary<string, Assembly>();
|
|
var exe = Assembly.GetEntryAssembly();
|
|
var exe = Assembly.GetEntryAssembly();
|
|
dic[exe.FullName] = exe;
|
|
dic[exe.FullName] = exe;
|
|
- var files = Directory.GetFiles(domain.BaseDirectory, prefix + "*.dll", SearchOption.AllDirectories);
|
|
|
|
|
|
+ var files = Directory.GetFiles(domain.BaseDirectory, "*" + dllKey + "*.dll", SearchOption.AllDirectories);
|
|
foreach (var item in files)
|
|
foreach (var item in files)
|
|
{
|
|
{
|
|
//如果一个dll在项目中被反射加载,这种情况需要需要从目录中检索dll
|
|
//如果一个dll在项目中被反射加载,这种情况需要需要从目录中检索dll
|
|
@@ -24,22 +24,22 @@ public static class AppDomainExtents
|
|
domain.GetAssemblies().ToList().ForEach(i =>
|
|
domain.GetAssemblies().ToList().ForEach(i =>
|
|
{
|
|
{
|
|
if (dic.ContainsKey(i.FullName)) return;
|
|
if (dic.ContainsKey(i.FullName)) return;
|
|
- if (i.FullName != null && i.FullName.ToUpper().StartsWith(prefix.ToUpper()))
|
|
|
|
|
|
+ if (i.FullName != null && i.FullName.ToUpper().Contains(dllKey.ToUpper()))
|
|
dic[i.FullName] = i;
|
|
dic[i.FullName] = i;
|
|
- GetReferanceAssemblies(i, dic, prefix);
|
|
|
|
|
|
+ GetReferanceAssemblies(i, dic, dllKey);
|
|
});
|
|
});
|
|
var res = dic.Values.OrderBy(p => p.FullName).ToArray();
|
|
var res = dic.Values.OrderBy(p => p.FullName).ToArray();
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
- static void GetReferanceAssemblies(Assembly assembly, Dictionary<string, Assembly> dic, string prefix)
|
|
|
|
|
|
+ static void GetReferanceAssemblies(Assembly assembly, Dictionary<string, Assembly> dic, string dllKey)
|
|
{
|
|
{
|
|
assembly.GetReferencedAssemblies().ToList().ForEach(i =>
|
|
assembly.GetReferencedAssemblies().ToList().ForEach(i =>
|
|
{
|
|
{
|
|
if (dic.ContainsKey(i.FullName)) return;
|
|
if (dic.ContainsKey(i.FullName)) return;
|
|
- if (i.Name == null || !i.Name.ToUpper().StartsWith(prefix.ToUpper())) return;
|
|
|
|
|
|
+ if (i.Name == null || !i.Name.ToUpper().Contains(dllKey.ToUpper())) return;
|
|
var ass = Assembly.Load(i);
|
|
var ass = Assembly.Load(i);
|
|
dic[i.FullName] = ass;
|
|
dic[i.FullName] = ass;
|
|
- GetReferanceAssemblies(ass, dic, prefix);
|
|
|
|
|
|
+ GetReferanceAssemblies(ass, dic, dllKey);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|