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

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

    Maybe it's too late to answer here but hope that will solve someone's hectic problem.

    An automatic way to change assembly version of all of your projects using PowerShell script. This article will solve many of your problems.

    0 讨论(0)
  • 2020-11-22 15:28

    open up the AssemblyInfo.cs file and change

    // You can specify all the values or you can default the Build and Revision Numbers 
    // by using the '*' as shown below:
    // [assembly: AssemblyVersion("1.0.*")]
    [assembly: AssemblyVersion("1.0.0.0")]
    [assembly: AssemblyFileVersion("1.0.0.0")]
    

    to

    [assembly: AssemblyVersion("1.0.*")]
    //[assembly: AssemblyFileVersion("1.0.0.0")]
    

    you can do this in IDE by going to project -> properties -> assembly information

    This however will only allow you to auto increment the Assembly version and will give you the

    Assembly File Version: A wildcard ("*") is not allowed in this field

    message box if you try place a * in the file version field.

    So just open up the assemblyinfo.cs and do it manually.

    0 讨论(0)
  • 2020-11-22 15:29

    As of right now, for my application,

    string ver = Application.ProductVersion;
    

    returns ver = 1.0.3251.27860

    The value 3251 is the number of days since 1/1/2000. I use it to put a version creation date on the splash screen of my application. When dealing with a user, I can ask the creation date which is easier to communicate than some long number.

    (I'm a one-man dept supporting a small company. This approach may not work for you.)

    0 讨论(0)
  • 2020-11-22 15:30

    There is a visual studio extension Automatic Versions which supports Visual Studio (2012, 2013, 2015) 2017 & 2019.

    Screen Shots

    0 讨论(0)
  • For anyone using Tortoise Subversion, you can tie one of your version numbers to the subversion Revision number of your source code. I find this very useful (Auditors really like this too!). You do this by calling the WCREV utility in your pre-build and generating your AssemblyInfo.cs from a template.

    If your template is called AssemblyInfo.wcrev and sits in the normal AssemblyInfo.cs directory, and tortoise is in the default installation directory, then your Pre-Build command looks like this (N.B. All on one line):

    "C:\Program Files\TortoiseSVN\bin\SubWCRev.exe" "$(ProjectDir)." "$(ProjectDir)Properties\AssemblyInfo.wcrev"  "$(ProjectDir)Properties\AssemblyInfo.cs"
    

    The template file would include the wcrev token substitution string: $WCREV$
    e.g.

    [assembly: AssemblyFileVersion("1.0.0.$WCREV$")]
    

    Note:
    As your AssemblyInfo.cs is now generated you do not want it version controled.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题