简体   繁体   English

如何在运行时检索有关已加载程序集的信息? (C#、. NET)

[英]How to retrieve info on a loaded assembly at runtime? (c# , .NET)

In .NET c# 3.5 I have a console application (A) that references several assemblies(X, Y, Z). 在.NET c#3.5中,我有一个控制台应用程序(A),该应用程序引用了几个程序集(X,Y,Z)。

How can I get the version information of the loaded assemblies at run time? 如何在运行时获取已加载程序集的版本信息?

I can use reflection to get the info on the currently executing assembly like this 我可以像这样使用反射来获取有关当前正在执行的程序集的信息

System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()

but not the loaded assemblies. 但不加载的程序集。 Thanks for your help! 谢谢你的帮助!

您可以从AppDomain获取加载的程序集列表

var la = AppDomain.CurrentDomain.GetAssemblies();

JP's answer will give you all of the assemblies in the AppDomain. JP的答案将为您提供AppDomain中的所有程序集。 If you only want the assemblies that your current assembly references directly, you can use: 如果只希望当前程序集直接引用的程序集,则可以使用:

var names = Assembly.GetExecutingAssembly().GetReferencedAssemblies();

That will give you the names, including version information. 这将为您提供名称,包括版本信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM