获取依赖程序集?
有没有办法获取依赖于给定程序集的所有程序集?
伪:
Assembly a = GetAssembly();
var dependants = a.GetDependants();
Is there a way to get all assemblies that depend on a given assembly?
Pseudo:
Assembly a = GetAssembly();
var dependants = a.GetDependants();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您希望从当前应用程序域中查找依赖程序集,您可以使用类似于下面定义的
GetDependentAssemblies
函数:analyzedAssembly
参数表示您要查找的程序集找到所有的家属。If you wish to find the dependent assemblies from the current application domain, you could use something like the
GetDependentAssemblies
function defined below:The
analyzedAssembly
parameter represents the assembly for which you want to find all the dependents.通过编程,您可以使用 Mono.Cecil 来执行此操作。
像这样的东西(请注意,如果附加了调试器,这将不起作用 - 例如,如果您从 VS 本身内部运行它):
如果您不需要以编程方式执行此操作,则 NDepend 或 Reflector 可以为您提供此信息。
Programatically, you can use Mono.Cecil to do this.
Something like this (note this won't work if the debugger is attached - e.g. if you run it from inside VS itself):
If you don't need to do this programatically, then NDepend or Reflector can give you this information.
首先定义您的范围,例如:
我的应用程序的 bin 目录中的所有程序集
我的应用程序的 bin 目录中的所有程序集 + GAC 中的所有程序集
世界上任何计算机上的所有程序集。
然后简单地 (*) 迭代范围内的所有程序集,并使用反射来检查它们是否依赖于您的目标程序集。
如果您想要间接和直接引用,则必须对找到的所有程序集进行冲洗和重复。
(*) 如果您的范围是以上 3,则可能不会那么简单。
First define your scope, e.g.:
All assemblies in my application's bin directory
All assemblies in my application's bin directory + all assemblies in the GAC
All assemblies on any machine in the world.
Then simply (*) iterate through all assemblies in your scope, and use reflection to check if they depend on your target assembly.
If you want indirect as well as direct references, you'll have to rinse and repeat for all the assemblies you find.
(*) Might not be quite so simple if your scope is 3 above.
我不知道有任何内置的可能性可以在运行时获取依赖项。
所以我认为最简单的解决方案是定义一个扩展方法并使用 this 应用程序中的代码。我一年前使用过一个应用程序本身。但不要使用它的代码。
希望这有帮助。
I'm not aware of any built-in possibility to get dependencies at runtime.
So I think the easiest solution is define an extension method and use code from this application. I used an application itself a years ago. But do not use code of it.
Hope this helps.