自动更新版本号 [英] Automatically update version number

查看:128
本文介绍了自动更新版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望每个构建版本都增加我的应用程序的version属性,但是我不确定如何在Visual Studio(2005/2008)中启用此功能.我试图将AssemblyVersion指定为1.0.*,但它并不能完全满足我的需求.

I would like the version property of my application to be incremented for each build but I'm not sure on how to enable this functionality in Visual Studio (2005/2008). I have tried to specify the AssemblyVersion as 1.0.* but it doesn't get me exactly what I want.

我还在使用设置文件,并且在较早的尝试中,当程序集版本更改时,由于应用程序在另一个目录中查找设置文件,因此我的设置被重置为默认设置.

I'm also using a settings file and in earlier attempts when the assembly version changed my settings got reset to the default since the application looked for the settings file in another directory.

我希望能够以1.1.38的形式显示版本号,因此当用户发现问题时,我可以记录他们正在使用的版本,并告诉他们如果有旧版本则进行升级.

I would like to be able to display a version number in the form of 1.1.38 so when a user finds a problem I can log the version they are using as well as tell them to upgrade if they have an old release.

对于版本控制的工作原理的简短解释也将不胜感激.版本号和修订号何时递增?

A short explanation of how the versioning works would also be appreciated. When does the build and revision number get incremented?

推荐答案

有了内置"的东西,就不能了,因为使用1.0.*或1.0.0.*会将修订和内部版本号替换为编码的日期/时间戳,通常也是一种好方法.

With the "Built in" stuff, you can't, as using 1.0.* or 1.0.0.* will replace the revision and build numbers with a coded date/timestamp, which is usually also a good way.

有关更多信息,请参见程序集链接器/v标记中的文档.

For more info, see the Assembly Linker Documentation in the /v tag.

关于自动递增数字,请使用AssemblyInfo任务:

As for automatically incrementing numbers, use the AssemblyInfo Task:

AssemblyInfo任务

可以将其配置为自动增加内部版本号.

This can be configured to automatically increment the build number.

有2个陷阱:

  1. 版本字符串中的4个数字中的每个数字都限制为65535.这是Windows的限制,不太可能得到解决.
  1. Each of the 4 numbers in the Version string is limited to 65535. This is a Windows Limitation and unlikely to get fixed.
    • Why are build numbers limited to 65535?

然后检索版本号非常容易:

Retrieving the Version number is then quite easy:

Version v = Assembly.GetExecutingAssembly().GetName().Version;
string About = string.Format(CultureInfo.InvariantCulture, @"YourApp Version {0}.{1}.{2} (r{3})", v.Major, v.Minor, v.Build, v.Revision);


并且要澄清一下:在.net或至少在C#中,该内部版本实际上是THIRD号,而不是某些人(例如习惯于Major.Minor.Release.Build的Delphi开发人员)的第四个数字期待.


And, to clarify: In .net or at least in C#, the build is actually the THIRD number, not the fourth one as some people (for example Delphi Developers who are used to Major.Minor.Release.Build) might expect.

在.net中,它是Major.Minor.Build.Revision.

In .net, it's Major.Minor.Build.Revision.

这篇关于自动更新版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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