2
votes

In my release pipeline for a dotnet core project, I want to increment the assembly version automatically so I don't need to update it manually each time. This is so my Nuget version is increased every time.

At the moment I'm using the dotnet pack command and adding the build number at the end using the "Automated Package Versioning" set to "Use Environment Variable: Build.BuildNumber". Then I set the "Option > Build Number Format" to "1.0.$(BuildID)". First, I tried setting the attribute of the .csproj file to 1.0.$(BuildID), but the pipeline did not pick that up.

The problem is that I have to edit my build pipeline every time I want to adjust my major or minor semver version. Yet with the teams, we agreed not to put build pipeline config in source control (yaml files). Is there a way we can put a part of the build pipeline in a yaml file so that we can override parts of the configuration?

For example: I could set the "Build Number Format" to "$(Major).$(Minor).$(BuildID)" and then the partial yaml could override the Major and Minor variables.

1
Hi, did you exactly pick the value in $(BuildID) successfully? I'm a bit confused that in your third paragraph that you said the problem is about the Major and Minor variables.LoLance
I can't check in an azure-pipeline.yml. The ops department doesn't have access to our repo and wants to keep the pipeline under their control (we and them can access the pipeline online through a browser, but if we put the config in a yaml file, then the ops department can't update the pipeline). But we do want to put some values (like the Major and Minor variables) in a file in our repo, so we can update them without the ops department having a say in this. Because now the ops department could overwrite our major and minor versions.Ken Bonny

1 Answers

1
votes

How to set up automatic nuget version increments

If you want to automatic nuget version increments, you could use the BuildNumber $(Rev:r) instead of $(BuildID):

Run (build) number:

$(Rev:r)

2 (The third run on this day will be 3, and so on.)

Use $(Rev:r) to ensure that every completed build has a unique name. When a build is completed, if nothing else in the build number has changed, the Rev integer value is incremented by one.

If you want to show prefix zeros in the number, you can add additional 'r' characters. For example, specify $(Rev:rr) if you want the Rev number to begin with 01, 02, and so on.

So, you could set the Build Number Format to $(Major).$(Minor)$(Rev:.r).

Hope this helps.