This is the way I'm doing my versioning right now
variables:
major: '1'
minor: '1'
revision: $[counter(variables['minor'], 1)] # This will get reset every time minor gets bumped.
${{ if eq( variables['Build.SourceBranchName'], 'master' ) }}:
nugetVersion: '$(major).$(minor).$(revision)'
${{ else }} :
nugetVersion: '$(major).$(minor).$(revision)-$(Build.SourceBranchName)'
major and minor are changed manually, and whenever minor is changed, the revision resets back to 0, and keeps increasing with every pipeline that is ran. Now this works well if we only worked in master, but it's not as good when working in separate branches. Because the revision will keep incrementing even if we're working in a different branch, and thus the master version will no longer be coherent, skipping versions.
What is a good way to do this sort of automatic versioning? I was thinking of having the branch version be based on the latest master revision, and then keep incrementing a fourth digit after the branch name. Example with master being on 1.0.9, branch foo would have versions such as 1.0.9-foo.1, 1.0.9-foo.2, and so on.
This is just an idea but I don't know what's the best practice here or standard. Any ideas are appreciated



counterexpression will increase therevisionvalue for the pipeline between different branches. Hence, you need to use different yaml for same pipeline between branches. Please check the sample below, let me know if you have any queries, thanks.