基本上,我想在我的 MVC 站点内的页面上打印一个列表,其中显示应用程序使用的所有程序集以及版本信息。
我不想只将那些包含在 bin 目录中,我想使用更准确的方法。
所以例子是
我想知道正在使用 bin 目录中的哪些 dll。对于其中的每一个,我都需要查看它们的依赖程序集(及其版本信息)。
我想知道从 GAC 等引用了哪些 dll。
我希望获得尽可能多的相关信息,因此诸如程序集期望的版本以及应用程序正在获取的内容等信息将很有用。
是否有任何标准方法?
谢谢, 马丁
最佳答案
考虑使用 BuildManager.GetReferencedAssemblies
其中:
Returns a list of assembly references that all page compilations must reference.
示例用法:
var assemblies = BuildManager.GetReferencedAssemblies().Cast<Assembly>();
另请注意此方法与 AppDomain.GetAssemblies()
之间的重要区别。 BuildManager.GetReferencedAssemblies
返回:
assemblies specified in the assemblies element of the Web.config file, assemblies built from custom code in the App_Code directory, and assemblies in other top-level folders.
而 AppDomain.GetAssemblies()
仅返回当前加载的程序集。
关于c# - 我可以获取网站引用的所有程序集吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23290601/