开发者

Detecting Plugin assemblies under iis7

I have a c# assembly that is consumed by both websites and winform apps. Part of this dll has functionality whereby it checks for the presence of an optional plug-in dll and uses it if present. This works by scanning its local folder for dlls with a matching interface. So, an abbreviated form of what happens is:

Assembly executingAssembly = Assembly.GetExecutingAssembly();
foreach (FileInfo dllFile in exeLocation.GetFiles("*.dll"))
{
  assembly = Assembly.LoadFile(dllFile.FullName);
  foreach (Type exportedType 开发者_开发知识库in assembly.GetExportedTypes())
  {
    foreach (Type interfaceType in exportedType.GetInterfaces())
    {
      if (interfaceType == typeof(IMyInterface))
     {
         //Found it!
      }
    }
  }
}

Unfortunately, when running under iis7, it appears to create a shadow copy under \Temporary ASP.NET Files where each dll sits in its own folder so exeLocation.GetFiles only returns a single dll (itself). I need a solution that will work for all winforms, webforms, services, etc (preferably without changing iis7 config)

Any ideas?


DirectoryInfo location;
if(HttpRuntime.AppDomainAppId != null) {
    location = new DirectoryInfo(Path.Combine(HttpContext.Current.Server.MapPath("~/bin")));
} else { 
    location = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
}

foreach (var file in location.GetFiles("*.dll"))
{
    // your code
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜