How to set assembly version to Jenkins build number?

后端 未结 3 1706
遇见更好的自我
遇见更好的自我 2020-12-30 14:44

I am using \"Change Assembly Version\" plug-in in Jenkins to update all AssemblyInfo.cs files of my ASP.NET MVC project to apply version number during build process. If I se

相关标签:
3条回答
  • 2020-12-30 14:55

    For others looking to update just 1 number of the version number but keep the rest of the existing version numbers you can set up the "Change Assembly Version" plug-in as follows:

    Assembly Version: $BUILD_NUMBER
    FileName: <project folder>/Properties/AssemblyInfo.cs
    RegexPattern: Assembly(\w*)Version\("(\d+).(\d+).(\d+).(\d+)"\)
    ReplacementPattern: Assembly$1Version("$2.$3.%s")

    This will keep the existing, first 2 numbers already contained in the Assembly???Version settings and set the 3rd version number to the current Jenkins build number.

    Example

    AssemblyInfo.cs contains:

    [assembly: AssemblyVersion("1.40.0.0")]
    [assembly: AssemblyFileVersion("1.40.0.0")]
    

    If the Jenkins build number is 103, then after the above settings are used by the Change Assembly Version plugin the AssemblyInfo.cs will contain:

    [assembly: AssemblyVersion("1.40.103.0")]
    [assembly: AssemblyFileVersion("1.40.103.0")]
    

    Note

    If you are using subversion (and likely other source control systems) and are using the "Check-out Strategy" of "Use SVN update as much as possible" you will have to change it to "Use SVN update as much as possible with svn revert before update" to ensure that the modified AssemblyInfo.cs file is reset for the next build.

    0 讨论(0)
  • 2020-12-30 14:59

    The previous answer about how to use "Change Assembly Version" plugin for Jenkins doesn't work. In my AssemblyInfo.cs files I usually set them up with auto incrementing version to help local dev work.

    Example

    AssemblyInfo.cs contains:

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

    After the Jenkins build if the version is 10 then AssemblyInfo.cs will contain:

    [assembly: AssemblyVersion("1.0.10")]
    [assembly: AssemblyFileVersion("1.0.10")]
    

    The plugin is used like so to achieve the above:

    Assembly Version: $BUILD_NUMBER
    FileName: 
    RegexPattern: Assembly(\w*)Version\("(\d+).(\d+).(\*)"\)
    ReplacementPattern: Assembly$1Version("$2.$3.%s")
    

    One other error I got whilst using the plugin was the file permission didn't allow write access. In order to fix this find the AssemblyInfo.cs and disable "Read Only".

    Hope to helps anyone.

    0 讨论(0)
  • 2020-12-30 15:09

    Cool, I found the answer myself.

    basically, I had to give "1.0.0.$BUILD_NUMBER" in the "Assembly Version" field of the "Change Assembly Version" plugin

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