How can I get the build number of a Visual Studio project to increment?

大憨熊 提交于 2019-12-14 01:09:35

问题


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

I've got this in AssemblyInfo.cs:

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

...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);

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

...to:

Version 1.5.5465.25999

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?

UPDATE

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());

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")

回答1:


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.



来源:https://stackoverflow.com/questions/27557023/how-can-i-get-the-build-number-of-a-visual-studio-project-to-increment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!