Automatically update version number

前端 未结 7 1373
南笙
南笙 2020-11-28 02:33

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 ha

7条回答
  •  执笔经年
    2020-11-28 02:55

    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.

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

    As for automatically incrementing numbers, use the AssemblyInfo Task:

    AssemblyInfo Task

    This can be configured to automatically increment the build number.

    There are 2 Gotchas:

    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?
    2. Using with with Subversion requires a small change:
      • Using MSBuild to generate assembly version info at build time (including SubVersion fix)

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

    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.

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

提交回复
热议问题