如何确定 GAC 程序集的最新版本号

发布于 2024-08-07 17:59:51 字数 237 浏览 1 评论 0原文

我正在尝试为我的应用程序创建一个诊断日志,该日志将显示 GAC 中安装的程序集的最新版本号。例如,GAC 中同一程序集有两个版本:foo.dll 版本 1.0.0.0 和 foo.dll 版本 2.0.0.0。我需要一个如下所示的功能:

GetLatestGacVersion("foo.dll");  // returns "2.0.0.0"

有人知道最好的方法吗?

谢谢!

I'm trying to create a diagnostic log for my application that will display the latest version number of an assembly installed in the GAC. For example, there are two versions of the same assembly in the GAC: foo.dll version 1.0.0.0 and foo.dll version 2.0.0.0. I need a function like the following:

GetLatestGacVersion("foo.dll");  // returns "2.0.0.0"

Anyone know the best way to do this?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔少女心 2024-08-14 17:59:51

最简单的是:

Assembly a = Assembly.LoadWithPartialName ("foo.dll");
return a.GetName ().Version

它将自动为您提供 GAC 的最新版本程序集。

请注意,该方法已被弃用,这是有充分理由的。向 GAC 请求非特定版本可能会造成很多麻烦。

如果不真正知道你想做什么,就很难给出进一步的建议,但一般来说,如果你正在寻找一个特定的版本,你应该探索它,而不是仅仅加载“某些东西”。

Easiest is:

Assembly a = Assembly.LoadWithPartialName ("foo.dll");
return a.GetName ().Version

which will automatically give you the latest-version assembly from the GAC.

Please note that the Method is deprecated for good reasons. Asking for an unspecific version from the GAC is going to possibly cause lots of trouble.

Without really knowing what you want to do it's hard to give further advice, but in general if you are looking for a specific version you should rather probe for it instead of just loading "something".

最美的太阳 2024-08-14 17:59:51

Fusion API 周围使用托管包装器( fusion.dll),您可以枚举 GAC 中的程序集,按名称过滤它们并按版本排序。

Using a managed wrapper around the Fusion API (fusion.dll) you could enumerate the assemblies in the GAC, filter them by name and order by version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文