-2

I have a .NET 8 web application that displays the product's version to the user. Within the csproj file i have the following setting among others:

<PropertyGroup>
    <VersionPrefix>1.0.0.1</VersionPrefix>
</PropertyGroup>

Instead of manually updating the build value 1.0.0.[1] from time to time I would like this value to be updated automatically with the current build's changeset. This could be done either when checking in code or when publishing/building. Either works for me.

For example if I published changeset 1423 I would expect the version to be 1.0.0.1423.

I have seen a couple posts but they all mention getting the latest TFS changeset rather than the current build changeset which would create an issue if I were to publish an older build.
I am not sure if this is even possible but I will gladly listen to suggestions.

1 Answer 1

0

In pipelines, you can use the predefined variable "Build.SourceVersion" to get the changeset which the current build is running for.

enter image description here

For your case, you can set a pipeline variable 'VerPrefix' and set it value as '1.0.0.$(Build.SourceVersion)'.

enter image description here

When evaluating the pipeline variable 'VerPrefix', the expression '$(Build.SourceVersion)' will be parsed as the actual changeset. For example, when the changeset is '77', the value of 'VerPrefix' will be evaluated as '1.0.0.77'.

In the pipeline, you can use the .NET Core task to run the 'dotnet build' or 'dotnet publish' command for the .csproj file of your .NET 8 web app, and add the argument '-p:VersionPrefix=$(VerPrefix)' to the command. This argument will use the value of 'VerPrefix' to override the original value '1.0.0.1' when building the web app.

enter image description here

enter image description here


Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.