EXE版本号——如何正确比较次要版本
Windows EXE 文件附加有版本号,由点分隔的四位数字组成(例如 1.0.0.0)。
问题:比较这些数字的正确方法是什么?特别地,1.15.0.0>1.15.0.0>1.15.0.0>1.15.0.0。 1.2.0.0(因为 15 > 2)还是反之亦然(因为,数学上,1.15 < 1.2)?
背景:我的一个应用程序已达到 3.9.*,我想知道我是否可以继续使用 3.10.*,而无需安装程序或其他比较版本号的组件造成麻烦。
Windows EXE files have version numbers attached to them, consisting of four digits separated by dots (e.g. 1.0.0.0).
Question: What is the correct way to compare these numbers? In particular, is 1.15.0.0 > 1.2.0.0 (since 15 > 2) or vice versa (since, mathematically, 1.15 < 1.2)?
Background: One of my applications has reached 3.9.* and I would like to know wheter I can continue with 3.10.* without installers or other components that compare version numbers causing trouble.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正确的方法是将每个组件(以句点“.”分隔)依次视为数字而不是字符串值。所以,是的 1.15.0.0 是 > 1.2.0.0
如果您使用 Powershell,它有一个内置版本对象(基于 .NET 的
System.Version
type):[version]
将为您执行此功能。[作为参考,各个组件为
Major.Minor.Build.Revision
]The correct way is to consider each component (delimited by periods '.') in turn as a numeric rather than string value. So, yes 1.15.0.0 is > 1.2.0.0
If you use Powershell it has a built-in version object (based on .NET's
System.Version
type):[version]
that will perform this functionality for you.[For reference, the individual components are
Major.Minor.Build.Revision
]如 MSDN 本页所述< /a>:
这意味着,给定格式为“Major.Minor.Release.Build”的两个版本,您可以确信最终总会有足够的数据将它们组装成 64 位无符号整数值,如下所示:
所以您现在可以比较两个 64 位值,例如:
抱歉 5 年后才解决这个问题,但我当时正在四处走动......
As stated in MSDN at this page:
This mean, given two versions in format "Major.Minor.Release.Build", you can be confident you'll always end up having enough data to assemble them into 64-bit unsigned integer values like this:
So you can now just compare two 64 bit values like:
Sorry for solving it after 5 years, but I was walking around...