读取WPF应用程序的程序集版本信息

发布于 2024-09-15 09:50:50 字数 395 浏览 1 评论 0原文

我正在读取 wpf 应用程序的版本信息,但没有获得在 AssemblyInfo.cs 文件中写入的正确版本。在我的文件中,

[assembly: AssemblyVersion("0.1.001")]
[assembly: AssemblyFileVersion("0.0.001")]

我正在使用此代码读取版本信息

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

,我正在获取此版本 0.1.1.0,它应该是 0.1.001

谢谢

I am reading version information of my wpf application, but I am not getting the correct version as I have write in AssemblyInfo.cs file. In my file there is

[assembly: AssemblyVersion("0.1.001")]
[assembly: AssemblyFileVersion("0.0.001")]

I am reading version information using this code

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

I am getting this version 0.1.1.0 and it should be 0.1.001

Thanks

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

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

发布评论

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

评论(2

謸气贵蔟 2024-09-22 09:50:50

Version 类的属性 MajorMinorBuildRevision 的类型int,而不是string。因此,当来自汇编版本的字符串被解析为 Version 类时,该字符串的各个部分将被转换为 int 表示形式。还有规则是指定版本字符串的第一个数字是 VersionMajor 组件:

"1" - 1.0.0.0
"1.2" - 1.2.0.0
"1.2.3" - 1.2.3.0
"1.2.3.4" 1.2.3.4

The properties Major, Minor, Build and Revision of class Version are of type int, not string. So when string from assembly version is parsed into Version class, the parts of this string will be converted to int representation. Also there are rule that first number of specified version string is Major component of Version:

"1" - 1.0.0.0
"1.2" - 1.2.0.0
"1.2.3" - 1.2.3.0
"1.2.3.4" 1.2.3.4
孤凫 2024-09-22 09:50:50

MSDN 文章,它说:

版本的所有组成部分必须是大于或等于0的整数

因此它要么向上舍入,要么删除尾随零以获得有效整数。

In the MSDN article, it says that:

All components of the version must be integers greater than or equal to 0

So it's either rounding up or removing trailing zeros to get a valid integer.

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