如何获得要递增的Visual Studio项目的内部版本号? [英] How can I get the build number of a Visual Studio project to increment?

查看:207
本文介绍了如何获得要递增的Visual Studio项目的内部版本号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在Visual Studio中构建项目不会增加内部版本号?

Why does building a project in Visual Studio not increment the Build number?

我已经在AssemblyInfo.cs中找到了它:

I've got this in AssemblyInfo.cs:

[assembly: AssemblyVersion("1.5.*")]

...这在frmAbout的构造函数中:

...and this in frmAbout's constructor:

Version versionInfo = Assembly.GetExecutingAssembly().GetName().Version;
String versionStr = String.Format("{0}.{1}.{2}.{3}", versionInfo.Major.ToString(), versionInfo.Minor.ToString(), versionInfo.Build.ToString(), versionInfo.Revision.ToString());
lblVersion.Text = String.Format("Version {0}", versionStr);

但是,在更改代码并构建项目后(右键单击项目名称> Build),versionInfo的Build部分不会增加. 关于"框中的标签来自:

Yet, after making a change to the code, and building the project (right-click project name > Build), the Build portion of the versionInfo is not incremented. The label in the "About box" goes from:

Version 1.5.5465.25383

...发送至:

Version 1.5.5465.25999

为什么内部版本号没有从5465增加到5466?为何修订"会跳616个档?后者只是一个随机值,还是源中已更改的字节数,还是什么?

Why hasn't the build number increased from 5465 to 5466? And why does "Revision" jump 616 notches? Is that latter just a random value, or the number of bytes that have changed in the source, or what?

那我怎样才能使内部版本号真正增加呢?

So how can I get the build number to actually increment?

是的,razcor是正确的,因为它显示为"5465"(今天,此后的任何一天都是YMWV):

Yep, razcor is right, as this shows "5465" (today, YMWV any day after this):

DateTime startDate = new DateTime(2000, 1, 1);
DateTime todaysDate = DateTime.Today;
int diffDays = (todaysDate.Date - startDate.Date).Days;
MessageBox.Show(diffDays.ToString());

然后,知道版本号(例如5465),就可以计算并显示生成日期:

And, knowing the build number (such as 5465), the build date can be computed and displayed:

DateTime computedDate = startDate.AddDays(diffDays);
MessageBox.Show(computedDate.ToLongDateString()); // shows today's date (such as what it is today, namely: "Thursday, December 18, 2014")

推荐答案

当您将"0"替换为"*"时,内部版本号和修订版号会自动递增,但不会以您(和我)的思维方式出现.此自动增量的规则是:内部版本号是自2000年1月1日以来的天数,内部版本是自午夜以来的秒数除以2.

When you replace the '0' with the '*' build number and revision number will autoincrement, but not in the way you (and I) could think. Rules of this autoincrement is: build number is the number of days since 1.1.2000 and revision is the number of seconds since midnight, divided by 2.

这篇关于如何获得要递增的Visual Studio项目的内部版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆