Can I automatically increment the file build version when using Visual Studio?

后端 未结 25 3016
-上瘾入骨i
-上瘾入骨i 2020-11-22 14:32

I was just wondering how I could automatically increment the build (and version?) of my files using Visual Studio (2005).

If I look up the properties of sa

25条回答
  •  梦谈多话
    2020-11-22 15:20

    How to get the version {major}.{year}.1{date}.1{time}

    This one is kind of experimental, but I like it. Inspired by Jeff Atwood @ CodingHorror (link).

    The resulting version number becomes 1.2016.10709.11641 (meaning 2016-07-09 16:41), which allows for

    • poor mans zero padding (with the stupid leading 1s)
    • nearly-human readable local DateTime embedded into the version number
    • leaving Major version alone for really major breaking changes.

    Add a new item to your project, select General -> Text Template, name it something like CustomVersionNumber and (where applicable) comment out the AssemblyVersion and AssemblyFileVersion in Properties/AssemblyInfo.cs.

    Then, when saving this file, or building the project, this will regenerate a .cs file located as a sub-item under the created .tt file.

    <#@ template language="C#" #>
    <#@ assembly name="System.Core" #>
    <#@ import namespace="System.Linq" #>
    
    //
    // This code was generated by a tool. Any changes made manually will be lost
    // the next time this code is regenerated.
    //
    
    using System.Reflection;
    
    <#
        var date = DateTime.Now;
        int major = 1;
        int minor = date.Year;
        int build = 10000 + int.Parse(date.ToString("MMdd"));
        int revision = 10000 + int.Parse(date.ToString("HHmm"));
    #>
    
    [assembly: AssemblyVersion("<#= $"{major}.{minor}.{build}.{revision}" #>")]
    [assembly: AssemblyFileVersion("<#= $"{major}.{minor}.{build}.{revision}" #>")]
    

提交回复
热议问题