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

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

    Setting a * in the version number in AssemblyInfo or under project properties as described in the other posts does not work with all versions of Visual Studio / .NET.

    Afaik it did not work in VS 2005 (but in VS 2003 and VS 2008). For VS 2005 you could use the following: Auto Increment Visual Studio 2005 version build and revision number on compile time.

    But be aware that changing the version number automatically is not recommended for strong-named assemblies. The reason is that all references to such an assembly must be updated each time the referenced assembly is rebuilt due to the fact that strong-named assembly references are always a reference to a specific assembly version. Microsoft themselves change the version number of the .NET Framework assemblies only if there are changes in interfaces. (NB: I'm still searching for the link in MSDN where I read that.)

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

    I have created an application to increment the file version automatically.

    1. Download Application
    2. add the following line to pre-build event command line

      C:\temp\IncrementFileVersion.exe $(SolutionDir)\Properties\AssemblyInfo.cs

    3. Build the project

    To keep it simple the app only throws messages if there is an error, to confirm it worked fine you will need to check the file version in 'Assembly Information'

    Note : You will have to reload the solution in Visual studio for 'Assembly Information' button to populate the fields, however your output file will have the updated version.

    For suggestions and requests please email me at telson_alva@yahoo.com

    0 讨论(0)
  • 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}" #>")]
    
    0 讨论(0)
  • 2020-11-22 15:22

    It is in your project properties under Publish

    http://screencast.com/t/Vj7rhqJO
    (~ http://screencast.com/t/Vj7rhqJO)

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

    I'm using this approach https://stackoverflow.com/a/827209/3975786 by placing the T4 template in a "Solution Items" and using it with "Add as Link" within each project.

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

    AssemblyInfoUtil. Free. Open-source.

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