Child pages
  • Change Assembly Version
Skip to end of metadata
Go to start of metadata

View change-assembly-version-plugin on the plugin site for more information.

This plug-in change the [AssemblyVersion] and [AssemblyFileVersion] from AssemblyInfo.cs sources.

Description

The plugin will change the AssemblyVersion of all files named AssemblyInfo.cs (or other inserted) under the workspace folder.
It's recommended use the plugin with the default templates that are generated with visual studio.

Usage

Specify the version you want to change adding the Change assembly version in build step, and putting the version you want in the Assembly version input, like the image below

You can insert a hardcoded version like "1.0.5", but the plugin don't support syntax like 1.0.%someVariable% yet.

If you are attempting to use a version number with variable or regex or other combinations: 

  • %s in "ReplacementPattern" field will be replaced by "Assembly Version" field (uses java format string variables)
  • You can use regex grouping also: 
    • RegexPattern:
      Assembly(\w*)Version\("[0-9\*\.]+"\)
    • ReplacementPattern:
      Assembly$1Version("%s")

This will find both AssemblyVersion and AssemblyFileVersion and replace with the version specified in "Assembly Version" field.

Changelog

Release 1.4

Support to set the regex to change the version,

Thanks to pjangam

Release 1.3

Now it can receive various assemblies files, separeted by comma, like:

AssemblyInfo.cs, AssembliSomeThingInfo.cs

Release 1.2

Add a field to specify the name of the AssemblyInfo file instead of only the AssemblyInfo.cs

Release 1.1

Initial Release of the plugin.

Sponsors

42 Comments

  1. Hi Leonardo Kobus,

    It is a very good plugin and very useful for any .Net guy who is using Builds via Jenkins.

    We are using CommonAssemblyInfo.cs instead of AssemblyInfo.cs. Can you please give an additional Features to mention another file name instead of hardcoded "AssemblyInfo.cs"

    I think it will also helpful for other.

    1. Hi Nagar, I'm going to try release this feature today, if I can't, the release comes in monday

      Regards.

      1. Thanks Leonardo Kobus, 

        for your quick response and updated release.

  2. Hi Kobus,

    This plugin did not working with MultiJob plugin.

    If I select New Project as MultiJob Project, change Assembly Version does not comes in Add build Steps.

    Can you please look into it.

    Thanks

    Arpit Nagar

    1. Hi Nagar, made the modification to the release 1.2.1, soon will be disponible.
      Regards.

      1. Hi kobus,

        you works like a bullet. Thanks for your quick response :)

  3. Hi Kubos,

    Can you please provide a functionality to pass multiple file name [may be "," seperated values] like [CommonAssemblyInfo.cs ,  AssemblyInfo.cs]

    So that if any solution have multiple AssemblyInfo with different names can have proper Assembly Info.

    Thanks 

    Arpit

    1. Hi, nagar I'm out of time this week, I'll try to make this modification next week.

      As workaround now, you can call various change assembly version in your build step, each one pointing to a diferent file.
      regards.

      1. Hi Kobus,

        Thanks for your quick fix, but I have plenty of jobs. So I am avoiding to do this. I can wait till permanent solution.

        Did you get time, to look into it.

        Thanks 

        Arpit Nagar

        1. Hi nagar, I made the modification and released today! soon will be disponible.

          Thanks!

  4. Hi,

    I have tried this plugin with simple 1.0.0.1 assembly version, but after it worked, it got '?' in front of each assemblyinfo.cs file. Assembly version has changed though. 

    1. Hello Igor, wich version of the plugin are you using?
      And how is your assembly Info File ? can you put a example (just the lines where contains the versions).

    2. I'm having the sample problem. Version 1.4.1 of the plug-in. A question mark is inserted as the first character of every AssemblyInfo.cs. msbuild fails with:

            Properties\AssemblyInfo.cs(1,1): error CS0116: A namespace cannot directly contain members such as fields or methods

      I think it's a real question mark, not a unicode indicator.

      EDIT: Looking at the code, FilePath.readToString() and write() are used. According to the documentation, readToString() uses "current system encoding". For Windows, that is code page 932, aka windows-31j. However, my AssemblyInfo.cs files are UTF-8. I believe that Visual Studio uses UTF-8 by default. So perhaps the solution is to use core Java classes that can deal with different encodings. I am not a Java programmer, so I don't know what those would be.

      1. Hi Andy, I created a Jira

        https://issues.jenkins-ci.org/browse/JENKINS-25476

        So you can folow to see when its fixed.

        Just as workaround u can change the encoding? I work with VS 2013 and didn't notice the problem, I gonna need some time to analyze.

        Thanks.

        1. Thanks Leonardo, I changed the encoding and that did solve my problem for now.

          1. Hi Andy, Where and how did you change the encoding?

  5. Hi,

    Can someone please provide a sample assemblyinfo.cs and Jenkins settings?

    To me it's unclear what placeholders to use and what Jenkins ssettings to use.

    Thanks

    Mark

    1. Mark are you new to Jenkins or just the plugin?

      The plugin by default is used to change assembly version from the original template that VS creates.

      If you have custom files you can use the regular expression to change the correct session of you version file.

      1. It's ok.  I resolved this in the end.  I thought that I would have to put some sort of place holder into the assemblyinfo.cs, but it seems I didn't.

        $

        Unknown macro: {PIPELINE_VERSION}

        didn't work for me, but $

        Unknown macro: {BUILD_NUMBER}

        did

        1. Mark, that's because in the example PIPELINE_VERSION was a generated variable that other plugin create.
          You can use any variable that jenkins creates before the call of assembly version plugin.
          By default I think only build number was created by Jenkins, you can use others plugin to mix with this like : https://wiki.jenkins-ci.org/display/JENKINS/Version+Number+Plugin the generated version variable you can put to replace in assembly files, that was the purpose when I created that.

  6. I must be slow but I am not getting anywhere with this. Could someone please kick back onto the correct path.

    Here is what I have configured..............

    Build Environment

    Create a formatted version number

    Environment Variable Name               $CURRENTBUILD
    Version Number Format String           1.0.$

    Unknown macro: {SVN_REVISION}

    .$

    Unknown macro: {BUILD_NUMBER}

    Prefix Variable                                   $CURRENTBUILD
    Failed Builds                                    Don't increment builds today/ this month/ this year/ all time after a failed build      
    Build Display Name                           Use the formatted version number for build display name.
    Project Start Date                             2014-06-11
    Number of builds today
    Number of builds this month
    Number of builds this year
    Number of builds since the start of the project

    I must not be understanding something. I would like the AssemblyVersion changed to what is in the Version Number Format String but that does not seem to be happening.

    Any and all help appreciated!

    Doug

  7. Hi Mr.Kobus, 

    I've got this in a powershell script. 

    $assemblyPattern = "[0-9](\.([0-9]|*))

    Unknown macro: {1,3}

    "
        $assemblyVersionPattern = 'AssemblyFileVersion("([0-9](\.([0-9]|*))

    )")'
    $assemblyPattern = "[0-9](\.([0-9]|*))

    Unknown macro: {1,3}

    "

    $assemblyVersionPattern = 'AssemblyFileVersion("([0-9](\.([0-9]|*))

    )")'

    How do I put this info into the plugin? I think I might be messing with the syntax. Thanks 

    1. Hi Zaman, let me see if i understand your problem.
      Are you using a powershell to update and now want to use the plugin?

      If yes than you REgex pattern you have to put on the "Regex Pattern option in the plugin" you dont need to use any powershell script to call the plugin.

      Is that what you want? if no can you explaint better what are you trying to do?

      [] ' s

  8. I'm trying to use this plug-in and when it modifies the AssemblyInfo.cs file, the first character in the edited file is '?' which causes the build to fail (for obvious reasons).  Any ideas why it is doing this?  I looked at the source code and it doesn't look like it should do this, so any thoughts would be appreciated.

    Thanks,

    Desiree

    1. I found the answer to my problem in the issues list: Jenkins-25476

      The work-around is to save the Assembly file in UTF-8 (without BOM).

  9. Hello , 

    First of all i would like to thank the creator of this Plugin , it should resolve a lot of Versioning related issues i have ,

    The question is how do i set it up ?

    I would like the version to be for example 6.0.82.$

    Unknown macro: {Jenkins Build Number}

    how can i set it up  ?

    Thanks in advance  

    1. Ok , 

      It worked with  : 6.0.82.$

      Unknown macro: {BUILD_NUMBER}

      But the issue is that the files are imported from TFS with a "Read Only" Flag active , 

      So when trying to run the plugin i get : Finished getting version 'C52354'.
      Run condition Always enabling prebuild for step BuilderChain
      Run condition Always enabling perform for step BuilderChain
      Changing the file(s) D:\BuildAreas\Jen-Dev3\Source\GlobalAssemblyInfo.cs to version : 6.0.82.123
      java.io.IOException: Expecting Ant GLOB pattern, but saw 'D:\BuildAreas\Jen-Dev3\Source\GlobalAssemblyInfo.cs'. See http://ant.apache.org/manual/Types/fileset.html for syntax

      Any idea for a workaround or a solution for this issue?

  10. Ok , A Correction , I added a batch to remove the read-only flag and still getting the Error Above . 

    1. Hi Yonnatan, let me see before call the plugin to update Assemblies files you have some routine that get files from TFS? 

      Didn't understand very well, is this what he write 'C52354' or you can't write anything?

      [] ' s

      1. Yes , i use TFS Plugin to Import the latest code from our TFS Source Control 

        The C52354 is generated automaticly by the TFS .

        Br

        Yonnatan

  11. I am receiving:

    Updating file : D:\Jenkins\<PROJECT>\Properties\AssemblyInfo.csjava.io.FileNotFoundException: D:\Jenkins\MS-Main-CI\workspace\<PROJECT FOLDER>\Properties\AssemblyInfo.cs (Access is denied)
    at java.io.FileOutputStream.open(Native Method)

    Does the TFS build user need special access? Has anyone had this happen?

    1. I figured it out. The TFS plug-in pulls files read-only (duh!) and I had to create a powershell script to set them as writable:

      AssemblyInfoFiles = Get-ChildItem -Filter 'AssemblyInfo.cs' -Recurse
      Foreach( $file in $AssemblyInfoFiles )
      {
         if( $file.IsReadOnly )
         

      Unknown macro: {      $file.IsReadOnly = $false   }

         $file.IsReadOnly
      }
      $AssemblyInfoFiles = Get-ChildItem -Filter 'AssemblyInfo.cs' -Recurse

      Foreach( $file in $AssemblyInfoFiles )

      {

         if( $file.IsReadOnly )

         

      Unknown macro: {       $file.IsReadOnly = $false    }

         $file.IsReadOnly

      }

      I think this can be changes to a one-line script, but I am leaving mine for reference. Thanks!

  12. Nice plugin, thanks. It would be very nice if the build number could be used as a source for the Token Macro Plugin

    This way you could see what build number are you using (both major and minor version) in the same place, right on the main page of your build plan

  13. Hi,

    is it possible to use this plugin in a Jenkins 2.0 Pipeline Jenkinsfile?

    If not, are there any plans to implement this?

  14. I have downloaded and installed the 1.5.1 version of the plugin and I have an issue in that it is putting a question mark as the first character in the file, causing my builds to fail.

    Is this a bug in the software or how I have it setup?

    Craig

    1. I am also seeing this issue.  I installed 1.5.1 on a new jenkins environment (version 2.32.2), where my old jenkins environment had 1.5.1 and is Jenkins version 1.644.  The old Jenkins version does not have this issue, but the 2.32.2 does.

      Builds fail due to a ? being inserted at the beginning of the file

      What is different between the two (other than version) is that the newer setup has Jenkins running on Linux, but executing builds on Windows.  The older version is a single instance Jenkins where Jenkins and builds occur on the same instance.

  15. Hi Leonardo,

    I want to use the ${RELEASE_VERSION} to be changed at the Assembly file but only work when a Release is build. If I try a common Build, the plugin crash.

     I think could be a option like, I "declare" some VARS separated by ';' and the plugin uses the first one founded.

    Ex: 

    So, the plugin try the BUILD_NUMBER, if is a empty VAR, try the next on which is RELEASE_VERSION ....

  16. I have version 1.5.1 installed and am running into an issue where one file is getting updated but another is not even though the logs say both files are updated. 

    https://stackoverflow.com/questions/47895504/jenkins-change-assembly-version-plugin-not-updating-assemblyinfo-cs-file-in-asp

     

    1. Removed Stack Overflow and added bug  JENKINS-48641 - Getting issue details... STATUS

    2. I solved my own issue.  There was a slight difference between files that I didn't notice for far too long.

Write a comment…