depends.exe工具可以遍历可执行文件所依赖的所有dll,但是如果在运行时动态地由Assembly类加载DLL,我如何才能看到已经加载的DLL(程序集)?
作为快照:
AppDomain.CurrentDomain.GetAssemblies()
Run Code Online (Sandbox Code Playgroud)
当它们发生时:
AppDomain.CurrentDomain.AssemblyLoad
Run Code Online (Sandbox Code Playgroud)
就像是:
static void Main()
{
AppDomain.CurrentDomain.AssemblyLoad += AssemblyLoad;
LogCurrent("before");
AnotherMethod();
LogCurrent("after");
}
static void AnotherMethod()
{
// to force stuff to happen
new System.Data.SqlClient.SqlCommand().Dispose();
}
static void LogCurrent(string caption)
{
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine(caption + ": " + asm.FullName);
}
}
static void AssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
Console.WriteLine("Loaded: " + args.LoadedAssembly.FullName);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2943 次 |
| 最近记录: |