跳到主要内容

Getcallingassembly Getentryassembly Getexecutingassembly

获取程序集新的三个方法

GetEntryAssemblyGetCallingAssemblyGetExecutingAssembly

顾名思义

GetEntryAssembly:入口程序集,启动应用的.exe文件。GetExecutingAssembly:当前执行代码所在的程序集,可能是.dll或.exe。GetCallingAssembly:调用当前方法的上层方法所在的程序集。

三者的直观对比

场景GetEntryAssemblyGetExecutingAssemblyGetCallingAssembly程序A.exe 调用B.dll返回A.exe返回B.dll返回A.exe程序A.exe 引用了 B.dll,B.dll中调用了C.dll的方法返回A.exe返回C.dll返回B.dll

总结

GetEntryAssembly:找“源头”。GetExecutingAssembly:找“自己”。GetCallingAssembly:找“上级”。