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

后端 未结 25 2930
-上瘾入骨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:33

    Cake supports AssemblyInfo files patching. With cake in hands you have infinite ways to implement automatic version incrementing.

    Simple example of incrementing version like C# compiler does:

    Setup(() =>
    {
        // Executed BEFORE the first task.
        var datetimeNow = DateTime.Now;
        var daysPart = (datetimeNow - new DateTime(2000, 1, 1)).Days;
        var secondsPart = (long)datetimeNow.TimeOfDay.TotalSeconds/2;
        var assemblyInfo = new AssemblyInfoSettings
        {
            Version = "3.0.0.0",
            FileVersion = string.Format("3.0.{0}.{1}", daysPart, secondsPart)
        };
        CreateAssemblyInfo("MyProject/Properties/AssemblyInfo.cs", assemblyInfo);
    });
    

    Here:

    • Version - is assembly version. Best practice is to lock major version number and leave remaining with zeroes (like "1.0.0.0").
    • FileVersion - is assembly file version.

    Note that you can patch not only versions but also all other necessary information.

提交回复
热议问题