5

According to the documentation when dotnet gitversion is called with /updateassemblyinfo parameter it will recursively search for all AssemblyInfo.cs files in the git repo and update them. It will update the following assembly attributes:

  • AssemblyVersion will be set to the AssemblySemVer variable.
  • AssemblyFileVersion will be set to the MajorMinorPatch variable with an appended .0.
  • AssemblyInformationalVersion will be set to the InformationalVersion variable.

These variables currently have the following values according to the output from dotnet gitversion called without any parameters (copied from the entire JSON):

  • AssemblySemVer: 1.2.0.0
  • MajorMinorPatch: 1.2.0
  • InformationalVersion: 1.2.0-branch-name.1+104.Branch.branch-name.Sha.f00e3376da35703ab5e5527e44e942e7bd98s098

The question: is it possible to alter values in these variables in the predefined GitVersion.yml or somehow "on the fly" via parameters to dotnet gitversion?

The reason being my current project doesn't follow semver scheme historically and there is a need to set 3rd part of the version quartet to specific value every time regardless of branches, tags or any other git-specifics. For example our products versions looks like v1.2.50.10 or v02.04.30.01.

But it would be nice to use dotnet gitversion build-in ability to update AssemblyInfo.cs files even if we would not use it's full potential of semver compliant versioning.

Sevenate
  • 6,221
  • 3
  • 49
  • 75
  • Depending on how much of it you need/want have you looked at using SourceLink instead? Perhaps not applicable but throwing it out there just in case – pinkfloydx33 Feb 16 '21 at 18:20
  • `dotnet gitversion` has `/updateassemblyinfo` switch, did you try to use it? – Pavel Anikhouski Feb 16 '21 at 19:08
  • @PavelAnikhouski, yes I did - it is mentioned in the first line in the post :) The problem is I need to set all 4 parts of version quartet and in GitVersion.yml it seems I can only set first 3 (major, minor and patch) - the last will be always 0, but I need a way to set it as well. – Sevenate Feb 16 '21 at 19:19
  • @pinkfloydx33 what is SourceLink? – Sevenate Feb 16 '21 at 19:23
  • @Sevenate Sorry, I see. Their docs says that you can override only `tag-prefix` config value on the fly – Pavel Anikhouski Feb 16 '21 at 19:32
  • @PavelAnikhouski yes I've seen it and this is the only one override-able parameter as of now and it is not relevant, unfortunately. – Sevenate Feb 16 '21 at 20:25

1 Answers1

1

You can use environment variables to construct your version number or also GitVesrsion variables: https://gitversion.net/docs/reference/variables https://gitversion.net/docs/reference/configuration

For example, If you want to set the 3 the variable, in the informational version, with an environment variable and strictly increment the last one by using the CommitsSinceVersionSource GitVersion variable, you should add the following in you GitVersion.yml:

assembly-informational-format: '{Major}.{Minor}.{env:MY_NUMBER}.{CommitsSinceVersionSource}'

Geo
  • 1,167
  • 1
  • 10
  • 18
  • here you can find a complete example:https://github.com/geobarteam/AssemblyInfoGitVersion – Geo Mar 07 '22 at 08:59